iOS:HTTP直播到应用程序,视频赢得';不玩

iOS:HTTP直播到应用程序,视频赢得';不玩,ios,media-player,mpmovieplayercontroller,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 al

我已经准备好了一些视频文件,可以在我的服务器上播放。以下是我尝试在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中,视频播放效果会很好。所以我知道这个网址很好。但在我的应用程序中,我只是得到一个黑屏。我的代码有什么问题?

MPMoviePlayerController
需要是一个强属性,声明为so
@property(强,非原子)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];

MPMoviePlayerController
需要是声明为so
@property(强、非原子)的强属性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];

原因是需要保留
MPMoviePlayerController
,否则会立即释放。因为系统中没有任何东西保留它,所以您必须自己这样做。要保留它,你可以在你的类中建立一个强大的属性/实例,涵盖该工作。感谢你的解释。原因是需要保留
MPMoviePlayerController
,否则它将立即被释放。因为系统中没有任何东西保留它,所以您必须自己这样做。为了保留它,你可以在你的班级中建立一个强大的属性/实例,涵盖这项工作。感谢你的解释。