Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIMoviePlayerControllerDidEnterFullscreenNotification doesn't work in iOS8

Tags:

I am using UIWebView to play a youtube video with iFrame.
I am using UIMoviePlayerControllerDidEnterFullscreenNotification to detect youtube screen into fullscreen.
Like below code :

[[NSNotificationCenter defaultCenter] addObserver: self                                          selector: @selector(myMovieEnterFullScreen:)                                              name: @"UIMoviePlayerControllerDidEnterFullscreenNotification"                                            object: nil]; 

It works in iOS7.
But I try to run it in iOS8.
It doesn't work.
I think the notification name has be changed.
Has any alternative to detect the youtube fullscreen event in ios8?

like image 342
hsienwei Avatar asked Aug 29 '14 04:08

hsienwei


1 Answers

The implementation by markussvensson has some false alarms, since any UIWindowDidBecomeVisibleNotification is considered as a full screen video playback which is not true.

The implementation "AVPlayerItemBecameCurrentNotification" by Selvin can catch movie playback start, but cannot catch movie playback stop.

So I combined both implementations and it works as expected.

  1. Add observer to both AVPlayerItemBecameCurrentNotification & UIWindowDidBecomeHiddenNotification;

  2. When AVPlayerItemBecameCurrentNotification happens, set a flag;

  3. When UIWindowDidBecomeHiddenNotification happens, check the flag to see if it is a "video stop playing event".

BTW, AVPlayerItemBecameCurrentNotification is undocumented and might be broken for the next iOS major release.

like image 136
user1717750 Avatar answered Sep 23 '22 01:09

user1717750