在iOS sdk MPMoviePlayerController中播放视频时出现问题

在iOS sdk MPMoviePlayerController中播放视频时出现问题,ios,mpmovieplayercontroller,mpmovieplayer,movieplayer,Ios,Mpmovieplayercontroller,Mpmovieplayer,Movieplayer,我正在尝试在iPhone中播放视频,下面是我使用的代码 它一直在加载,但视频没有播放,我错过了什么 播放器已启动,但仅显示加载,从不播放视频 我还导入了MediaPlayer/MediaPlayer.h -(IBAction)play:(id)sender { NSBundle *bundle = [NSBundle mainBundle]; NSString *moviePath = [bundle pathForResource:@"test_output" ofType:@"mov"];

我正在尝试在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];
}
 }

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

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

NSURL *url = [NSURL URLWithString:moviePath];


我看不到任何调用_moviePlayer.moviePlayer的play方法的代码

尝试将以下语句添加到代码中

[u moviePlayer.moviePlayer play]

在[self.view addSubview:_moviePlayer.view]之前添加此语句


我希望这对你有用,伙计,你的代码似乎是正确的。问题肯定出在URL上。仔细检查url是否正确。

谢谢,亲爱的,fileurlwithpath工作正常。。你救了我一天。。。谢谢:)@Satish如果我的答案帮助您解决了问题,请将其标记为正确答案:)。
NSURL *url = [NSURL fileURLWithPath:moviePath];