0

我一直在尝试播放 mp4 文件,我正在从服务器接收 url,我已将其提供给 MPMoviePlayerController,播放器正在加载但文件未播放。这是代码...

    NSURL *url = [NSURL URLWithString:obj->msg_url]; // obj->url is a html php url not a direct file url.
    moviePlayer =  [[MPMoviePlayerController alloc]
                    initWithContentURL:url];

    moviePlayer.controlStyle = MPMovieControlStyleDefault; 
    moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];

所以在这种情况下,我如何使用 MPMoviePlayerController 从 html url 播放。任何的想法?

谢谢

4

2 回答 2

0

试试看 [moviePlayer play]; shouldAutoplay 似乎并不总是有预期的效果。

于 2012-10-18T08:07:56.180 回答
0

我已经先下载并播放它现在的工作。

        NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString  *documentsDirectory = [paths objectAtIndex:0];

        NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"sample.mp4"];
        [urlData writeToFile:filePath atomically:YES];


        NSURL *file_url = [NSURL fileURLWithPath:filePath];
        moviePlayer =  [[MPMoviePlayerController alloc]
                        initWithContentURL:file_url];

        moviePlayer.controlStyle = MPMovieControlStyleDefault;
        moviePlayer.shouldAutoplay = YES;
        [self.view addSubview:moviePlayer.view];
        [moviePlayer setFullscreen:YES animated:YES];
于 2012-10-18T08:57:20.030 回答