【问题标题】:Can't play movie in MPMovieplayercontroller无法在 MPMovieplayer 控制器中播放电影
【发布时间】:2015-12-29 17:05:22
【问题描述】:

我无法在MPMovieplayercontroller 中播放电影。我在谷歌上搜索了很多,但每次我得到一个黑屏。我也尝试检查isPreparedToPlay 属性,但它总是错误的。

self.moviePlayer = [[MPMoviePlayerController alloc] init];

[self.moviePlayer setContentURL:[self.videos objectAtIndex:0]];
NSLog(@"Playing videos : %@", [self.moviePlayer contentURL]);

 NSLog(@"Playing videos : %@", [[self.moviePlayer contentURL] absoluteString]);

[self.moviePlayer.view setFrame:CGRectMake (0, 0, 320, 460)];
[self.view addSubview:self.moviePlayer.view];
//self.moviePlayer.movieSourceType    = MPMovieSourceTypeFile;
/*[self.moviePlayer.view setFrame:self.view.bounds];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setShouldAutoplay:NO];*/  
[self.moviePlayer play];

首先 NSLog 打印一些奇怪的东西(为什么有“...”?):

/Users/Athos/Library/Developer/CoreSimulator/Devices/15855707-E728-4542-8DAA-3B71362D7DB6/data/Containers/Data/Applicati ... unny.mp4

但是第二个很好(我手动检查文件是否存在:

/Users/Athos/Library/Developer/CoreSimulator/Devices/15855707-E728-4542-8DAA-3B71362D7DB6/data/Containers/Data/Application/2ACD0002-1A1E-484C-B4E4-9486EBCFF74A/Documents/BuckBunny.mp4

你有什么线索吗? 提前致谢

【问题讨论】:

标签: ios objective-c iphone mpmovieplayercontroller


【解决方案1】:
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setContentURL:[NSURL fileURLWithPath:[self.videos objectAtIndex:0]]];
// Use FileURLWithPath 

【讨论】:

    【解决方案2】:

    试试这个:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/BuckBunny.mp4"];    
    NSURL *movieURL = [NSURL fileURLWithPath:path];
    
    self.moviePlayer = [[MPMoviePlayerController alloc] init];
    
    if(movieURL!=nil){
        [self.moviePlayer setContentURL:movieURL];
        [self.moviePlayer.view setFrame:CGRectMake (0, 0, 320, 460)];
        [self.view addSubview:self.moviePlayer.view];
        [self.moviePlayer play];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多