iOS:HTTP Live Streaming 到应用程序,视频无法播放

标签 ios media-player mpmovieplayercontroller http-live-streaming

我有一些视频文件可以在我的服务器上播放。这是我试图用来在 iOS 应用程序中播放它们的代码:

    Video *vid = [videos objectAtIndex:index];
    NSURL *vidUrl = [NSURL URLWithString:vid.videoUrl];
    NSLog(@"%@",vid.videoUrl);
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:vidUrl];
    player.controlStyle=MPMovieControlStyleEmbedded;
    [player.view setFrame:self.view.bounds];
    [self.view addSubview:player.view];
    [player play];

如果我将 NSLog 吐出的 URL 复制并粘贴到 Safari 中,则视频可以正常播放。所以我知道 URL 很好。但是在我的应用程序中,我只是黑屏。我的代码有什么问题?

最佳答案

MPMoviePlayerController 需要是这样声明的强属性 @property (strong, nonatomic) MPMoviePlayerController *mvpc;

然后每当你想播放一部电影时,你会写:

self.mvpc = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movieURL"]];
self.mvpc.shouldAutoplay = YES; //Optional
self.mvpc.controlStyle = MPMovieControlStyleEmbedded;
[self.mvpc prepareToPlay];
[self.mvpc.view setFrame:self.view.bounds];
[self.view addSubview:self.mvpc.view];
[self.mvpc play];

关于iOS:HTTP Live Streaming 到应用程序,视频无法播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20057206/

相关文章:

iOS - 将 UIMonthYearPicker 与 Interface Builder 结合使用

ios - Swift 如何根据内容设置 UIView 的高度限制

ios - 如何使 UISegmentedcontrol 透明?

java - MediaPlayer 出现错误

java - 更改 JavaFX MediaPlayer 播放速度

iphone - MPMovieplayerController 停止后保持下载 (iphone)

objective-c - 弹出 MPMoviePlayerController

iphone - Interface Builder 文件中的未知类 <MyViewController> + 本地化问题

Android,如何显示来自 onBufferingUpdate 的缓冲百分比

iphone - MOV 播放无法使用带有 MPMoviePlayerController 的 UIImagePickerController