gpt4 book ai didi

ios - 在 iOS sdk MPMoviePlayerController 中播放视频的问题

转载 作者:行者123 更新时间:2023-11-28 21:59:27 25 4
gpt4 key购买 nike

我正在尝试在 iPhone 中播放视频,以下是我使用的代码。

它一直在加载,但视频无法播放,我是不是遗漏了什么。

播放器已启动,但它只显示加载并且从不播放视频。

我还导入了MediaPlayer/MediaPlayer.h

-(IBAction)play:(id)sender
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test_output" ofType:@"mov"];


NSURL *url = [NSURL URLWithString:
moviePath];

_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
[_moviePlayer prepareToPlay];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}


- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];

if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}

As shown in screenshot it keeps loading only

最佳答案

首先,检查您的电影文件是否已添加到您的项目中。

其次,尝试使用 fileURLWithPath 创建路径。替换您的以下代码

NSURL *url = [NSURL URLWithString:moviePath];

NSURL *url = [NSURL fileURLWithPath:moviePath];

关于ios - 在 iOS sdk MPMoviePlayerController 中播放视频的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459053/

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