【问题标题】:Loading Video from NSURL从 NSURL 加载视频
【发布时间】:2014-02-19 01:25:14
【问题描述】:

我正在将视频保存到我的应用程序中的特定路径。

IE:

My Video Path is /private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4

然后我尝试在自定义帧中使用 MPMoviePlayerController 播放该视频。

videoPath = [stand stringForKey:@"videoPathKey"];
NSLog(@"My Video Path is %@", videoPath);
  MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]];
player.view.frame = CGRectMake(0, 44, 320, 272);
[self.view addSubview:player.view];
[self.view bringSubviewToFront:player.view];
[player play];

这似乎不起作用。视频永远不会加载。知道为什么吗?

是的,我得到了正确的 videoPath。

NSLOG 显示:URL 是 file:///private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_37794C4E-A3D0-4AC0-9964-A9DEBB61C3E2.mp4

【问题讨论】:

  • 请检查是否播放除mp4以外的其他视频格式。

标签: iphone objective-c sdk


【解决方案1】:
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Your VideoName" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];
mpMoviePlayerController.view.frame = CGRectMake(0, 0, self.playView.frame.size.width, self.playView.frame.size.height);
[self.playView addSubview:mpMoviePlayerController.view];
[mpMoviePlayerController play];

试试这个!

【讨论】:

    【解决方案2】:

    这就是我过去的做法

    - (MPMoviePlayerController *) loadFile:(NSString *) fileName intoView:(UIView*) videoView
    {
       NSString *thePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];
       NSURL *theurl = [NSURL fileURLWithPath:thePath];
       MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
       [moviePlayer.view setFrame:videoView.bounds];
       [videoView addSubview:moviePlayer.view];
       [moviePlayer setControlStyle:MPMovieControlStyleNone];
       [moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
       moviePlayer.shouldAutoplay = NO;
       return moviePlayer;
    }
    

    【讨论】:

      【解决方案3】:

      您应该更改 URL 以放置方案:

      NSURL *movieURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://localhost%@",url]];
      

      您的视频路径将是:file://localhost/private/var/mobile/Applications/57DBBE40-088E-48CD-AED7-9BDB8FF1E039/tmp/video_66C2B8C6-012C-4608-BA8C-97C7ABA0D721.mp4

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-15
        • 2012-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多