1

我无法在 MPMoviePlayerController 中显示 AirPlay 选项。它显示在命令中心,但我无法让它显示在我的应用程序中。我确实得到了“iPhone Speaker”选项(为什么??)和“iPhone”选项,而不是通常的“iPhone”和“AirPlay”选项。

这就是我初始化媒体播放器的方式:

filePath = [s objectForKey:kStrMergeFileKeyString];
NSURL *movieString = [NSURL fileURLWithPath:filePath];

NSLog(@"filepath %@", filePath);
NSLog(@"fileurl %@", movieString);

// Now set up the movie player controller and play the movie.
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: movieString];

self.moviePlayer = player;
if (self.moviePlayer) {

    [[self.moviePlayer view] setFrame:[self.view bounds]];  // frame must match parent view
    [self.view addSubview: [self.moviePlayer view]];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

    if ([moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
        [moviePlayer setAllowsAirPlay:YES];
    }

    self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
    self.moviePlayer.shouldAutoplay = YES;
    [self.moviePlayer play];

    [self.moviePlayer setFullscreen:YES];


} else {
    NSLog(@"Invalid file path");
}

到底是怎么回事?这是一个错误吗?

4

1 回答 1

0

自 iOS 8.0 起,Apple 已从控件中移除 AirPlay 按钮,现在可通过控制中心正式访问。如果您拉起控制中心,您将看到 AirPlay 按钮。

话虽如此,我已经通过将电影播放器​​控件样式设置为 MPMoviePlayerControlStyleNone 来解决此问题。在此之后,我使用 UISliders 和 UIButtons 为控件创建了自己的自定义 UI。然后我在电影播放器​​上将allowAirPlay设置为true。

然后,您可以使用 AirPlayDetector 类来检查它是否可用,如果可用,请添加适当的 AirPlay 按钮。

希望对您有所帮助,我将在完全实施后发布代码。

这是 ARC 兼容版本的 AirPlayDetector github。

干杯!

https://github.com/MobileVet/AirPlayDetector

于 2015-08-21T16:20:23.000 回答