1

I have an AVPlayerItem that I have been able to grab from my UIWebView (visiting a website with an AVPlayer/video-file in the HTML) using some AVPlayer callbacks in my ViewController.

I need to access the AVPlayer that has that item set as its AVPlayerItem.

As of now I am doing this by calling [TheAVPlayerItem valueForKey:@"player"]; but this is undocumented and not guaranteed to work in the future.

I'm looking for a more authoritative way of achieving this. I'd even be happy with literally starting at the UIWebView and looping down through all subviews (or sub-objects?) and grabbing any AVPlayer then checking if it has its AVPlayerItem set to my AVPlayerItem.... alas I don't know how to do that. But I have included my attempt at doing so:

//[TheAVPlayerItem valueForKey:@"player"];//undocumented and prone to breaking.

for (NSObject *anObject in [myWebView subviews]) {
    if ([anObject isKindOfClass:[AVPlayer class]]) {
        NSLog(@"Found an AVPlayer, now check if AVPlayerItem is a match");//never called
    } else {

    }
}

Of course the NSLog was never called.

Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • See http://stackoverflow.com/a/7244069/1226963 for a way to recursively dig through all subviews. – rmaddy Feb 05 '17 at 03:57
  • @rmaddy I have a hunch the AVPlayer isn't a subview, I might be wrong, I manually went 10 levels deep in the subview array and did not see a single AVPlayer object. – Albert Renshaw Feb 05 '17 at 04:06
  • `AVPlayer` is not a view itself. Log all of the subview class names and you might find some internal class that represents the player's view. – rmaddy Feb 05 '17 at 04:19

0 Answers0