YTPlayerView.m pauseVideo() does not pause the video if controls = 0 - youtube-api

Issue summary:
YTPlayerView.m pauseVideo() does not pause the video nor cause a state change to Paused if the video is loaded with controls = 0.
Steps to reproduce issue:
Load a video with loadWithVideoId:(NSString *)videoId playerVars:(NSDictionary *)playerVars
UPDATE - playerVars are:
NSDictionary *playerVars = #{
#"autohide" : #1,
#"autoplay" : #0,
#"controls" : #0,
#"enablejsapi" : #1,
#"playsinline" : #1,
#"fs" : #0,
#"showinfo" : #0,
#"modestbranding" : #1,
#"rel" : #1
};
call playVideo()
call pauseVideo()
Expected output:
The video should start playing, then pause. The callback on state change should be called when the video starts playing and again when it pauses.
Actual results:
The video starts playing but does not pause.
The state change callback is called when the video starts playing, but not thereafter.
Notes:
Immediately after loading the video, if the native YouTube controls are used first, then the API calls work correctly thereafter. So, if you load the video and then tap on the UIWebView to start playback, and then tap on it again to pause playback, the video starts and pauses correctly and the state change callback is called correctly. After doing this the playVideo() and pauseVideo() methods work as expected. However if you don't do this first then pauseVideo() will not work.
This may possibly be related to v0.1.3 as it was working correctly in a previous version.
Solved - this seems to be an Xcode simulator problem, as it works OK on a device (iPad 2 and iPad Mini).
Simulator version 9.0 (SimulatorApp-602 CoreSimulator-159)
Xcode version 7.0 beta (7A120f)

Related

AVCaptionSession and AVAudioSession cause AVPlayer pause to play

I found, if stop running AVCaptureSession, and change AVAudioSession category right after -AVPlayer:play function may cause player pause to play.
Code
Her are a video show this bug
It should switch between Capture and Player, one at once. But some time, stop capture will cause player stop play.
I found this code run as I expected in iOS 9.3, but in iOS 11.3 this bug always show.

AVPlayer seekToTime methods stopped working on iOS 9

I have been working on a Video Player which is streaming a video asset using HLS. Once I started debugging it on iOS 9, I noticed that the scrub feature stopped working properly. However, it still works on iOS 8 devices.
Looking more into the problem I narrowed that the issue must be in the seekToTime method calls.
The scrub flow is the following:
when scrub starts, the video is paused using AVPlayer pause instance method
when the scrub ends seek the time using AVPlayer seekToTime: instance method
After that play the video using AVPlayer play instance method
I tried some other options for changing the current playhead such as seekToTime:completionHandler:, but still the same result.
On iOS 9 release notes (https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/), I saw that they made some changes to the AVFoundation, so I wonder if there are any known issues related to this with the iOS 9 release?
I just came across this issue and thanks to your link, I found the solution.
This is from the release note:
In iOS 9, these operations interrupt only when AVPlayer object’s
playback rate is changed to a non-zero value through the rate property
or play method.
which means we have to set
player.rate = 1
before calling seekToTime
do not use player.pause before seekToTime
player.rate has nothing to do with that issue

Why does SKVideoNode automatically starts playing video on iOS9?

When initialising a SKVideoNode with a video URL in iOS9 the behaviour changed to automatically starting the video as soon as the node is added, i.s.o. after the play method is called in previous versions of iOS.
doing the following inside the SKScene init
SKVideoNode* videoNode = [SKVideoNode videoNodeWithVideoFileNamed:#"sample.m4v"];
[self addChild:videoNode];
is enough to see the video playing, while previous iOS versions (more logically) required to also call
[videoNode play];
before the video starts playing.
Is this an intended change? A possible workaround I see is always immediately calling pause after initialising a video but it's a bit weird this behaviour changed.
(it feels like a bug to be honest)
(I also found the iOS9 simulator to have issues with SKVideoNodes playing at all, you have to test this on a device)

Control the application from control center in iOS

I am using AVAudioPlayer in my iOS application and the following functionalities have been given.
1. Play
2. Pause
3. Next
4. Previous
My requirement is, I want to give these functionalities from control center. Is it possible?
Control Center uses same API as lock screen. The audio controls appear on lock screen when a properly configured AVAudioSession is active. In addition to that you need to use MPNowPlayingInfoCenter API to set correct media information.
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc]initWithImage:albumImage];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = #{
MPMediaItemPropertyTitle : aSong.songTitle,
MPMediaItemPropertyArtist : aSong.artistName,
MPMediaItemPropertyArtwork : artwork,
MPNowPlayingInfoPropertyPlaybackRate : 1.0f
};
See the questions below for more information:
Why do the Lock Screen audio controls disappear when I pause AVAudioPlayer?
AVAudioPlayer on Lock Screen

Continue playing audio from html5 player when in iOS background mode

We built our music-oriented app in html5 and javascript with Sencha touch. For distribution we wrapped it in xcode with UIwebView. Everything runs fine except one thing that does not work: audio playing in multitask mode.
I know the general idea: add the UIBackgroundModes in info.plist.
Done. Now we can play the audio even in background mode.
Until we reach the end of the song. To start the next song we have to bring the app to foreground again or we can hit the play or 'next song' button on the iPhone audio controller.
After some research I found a promising workaround at: " Entering background on iOS4 to play audio " where the workaround is to edit AVAudioSessionCategoryPlayback and work with the UIBackgroundTaskIdentifier.
The problem for me is (just like in any other fix I found so far) that those solutions always assume that the audio is played either with AVaudioPlayer or MPMusicPlayerController. But in my case I user neither, our audio is played by our html5 player wrapped in UIwebView.
Anyone has any advice on how to continue playing the audio in iOS multitask mode when the audio player is a html5/javascript player?
My app plays audio via an <audio> tag in html hosted in UIWebView, and it supports background playing.
As you suggest, you need to have the 'App plays audio' background mode defined in your plist.
Try adding this to your applicationDidFinishLaunching: handler:
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
Thanks, guys, but I ended up simply keeping the app busy in a loop when in background mode. This was enough to bridge the time when connecting to the next song on the playlist.
The code I used is similar to this one:
iPhone - Backgrounding to poll for events
You could try this, adding a function on the onend event.

Resources