0
votes

So I currently have a UIWebView that contains video player controls such as Play/Pause/Volume/ect and an AVPlayer instance that is a subLayer of the view. Currently, the video overlaps the player ui which is fine currently because the video is smaller than the controls so they dont overlap.

However, I am trying to add a fullscreen mode, and an extended display mode.

My question is, how would I add the AVPlayer inside the UIWebView without overlapping the controls, so that I can set the video to fullscreen but also overlay the controls over the video when needed?

Any help/direction would be appreciated.

Thanks

1

1 Answers

0
votes

Recently I had such a situation and I searched a lot. At the end I found two ways to do that.

  1. Most nice way: Simply implement your code using MPMoviePlayerController

    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
    [player prepareToPlay];
    [player.view setFrame: myView.bounds];  // player's frame must match parent's
    [myView addSubview: player.view];
    // ...
    [player play];    
    
  2. If you really want to use UIWebView then think about embedded HTML5 <video> tag.

    <video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>

and load the HTMLString with the method

- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

but personally I would prefer the first solution with autoplay enabled and you are getting your controls including for full-screen and AriPlay automatically.