user2891491
user2891491

Reputation: 361

Cordova/iOS: HTML5 video without sound stops music

I've programmed a Cordova app with some HTML5 video tags in it and want to deliver a "video preview" to my users (like facebook does). On iOS, you are not allowed, to set the volume of the video tag by Javascript, so we have to play videos without sound (we've converted the original video to a preview file without sounds). That's works fine but running us into the following situation:

If a preview file starts playing, all music from other apps (like Spotify) will be stopped. In our case, that's bad for the user experience.

My question now: Is there a "workaround" or plugin for that case?

BTW: We are using the videos inline, because we don't want to open the external iOS player:

<video webkit-playsinline preload="auto" data-bind="click:openVideo">
 <source type="video/mp4" src="{{videoLink}}">
</video>

Upvotes: 3

Views: 380

Answers (1)

gro
gro

Reputation: 755

You need to set an audio category. Add this to your appDelegate:

#import <AVFoundation/AVFoundation.h>

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
:
:
    //set audio category
    NSError *setCategoryError = nil;
    BOOL success = [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: &setCategoryError];

    if (!success) {
        /* handle the error in setCategoryError */
        NSLog(@"AVAudioSession EROR");
    }
:
:
}

Upvotes: 1

Related Questions