Cordova plays YouTube videos in the background
I know how to play YouTube videos in iOS Cordova, but when the app enters the background video, the video stops and I need to manually resume it.
How do I set up the correct background so that it keeps playing when the app enters the background?
I've done a lot of research already and tried to implement many solutions here from Stack Overflow related to this topic, but none worked for me. On their Q&A site, Apple posted this code:
#import <AVFoundation/AVFoundation.h>
AVPlayerItem *playerItem = <#Get your player item#>;
NSArray *tracks = [playerItem tracks];
for (AVPlayerItemTrack *playerItemTrack in tracks)
{
// find video tracks
if ([playerItemTrack.assetTrack hasMediaCharacteristic:AVMediaCharacteristicVisual])
{
playerItemTrack.enabled = NO; // disable the track
}
}
Unfortunately, I don't know how I can refer to the AVPlayer instance from the UIWebView, but that might be the approach.
Any ideas?
source to share
It would be helpful to know how you are currently playing the video, but have you tried using this plugin:
https://github.com/Glitchbone/CordovaYoutubeVideoPlayer
NB. after following the installation instructions, I had to manually copy my own plugin files to the iOS plugins folder to get it working. A sample project is included in the source.
source to share