gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:06:24 24 4
gpt4 key购买 nike

我有一些视频文件可以在我的服务器上播放。这是我试图用来在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com