【问题标题】:issue playing video in iOS sdk MPMoviePlayerController在 iOS sdk MPMoviePlayerController 中播放视频的问题
【发布时间】:2014-08-23 06:20:10
【问题描述】:

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

【问题讨论】:

    标签: ios mpmovieplayercontroller mpmovieplayer movieplayer


    【解决方案1】:

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

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

    NSURL *url = [NSURL URLWithString:moviePath];
    

    NSURL *url = [NSURL fileURLWithPath:moviePath];
    

    【讨论】:

    • 谢谢亲爱的,fileurlwithpath 工作..你救了我的一天...谢谢 :)
    • @Satish 如果我的回答帮助您解决了问题,请将其标记为正确的:)。
    【解决方案2】:

    我看不到任何调用 _moviePlayer.movi​​ePlayer 的播放方法的代码。

    尝试在您的代码中添加以下语句。

    [_moviePlayer.movi​​ePlayer 播放];

    在[self.view addSubview:_moviePlayer.view]之前添加这条语句;

    我希望这对你有用

    【讨论】:

      【解决方案3】:

      伙计,您的代码似乎是正确的。问题肯定出在 URL 上。仔细检查 url 是否正确。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-08
        • 1970-01-01
        • 1970-01-01
        • 2014-04-27
        • 1970-01-01
        • 1970-01-01
        • 2012-11-29
        • 2013-10-10
        相关资源
        最近更新 更多