1

我在播放基于 URL 的视频时遇到问题。这是我的代码:

-(void)clickplay
{ 
   NSURL *fileURL = [NSURL URLWithString:@"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
   MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:fileURL]; 
   [moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
   [self.view addSubview:moviePlayerController.view];
   moviePlayerController.fullscreen = YES;
   [moviePlayerController play];
}

它编译成功,播放器确实弹出了,但它只是一直在加载……我尝试多次更改 URL,但没有效果。谁能帮我解决这个问题?

4

3 回答 3

1
videoURL=[NSURL URLWithString:URL]];

    videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

    videoPlayer.view.frame = CGRectMake(0,0, 320, 480);

     [videoPlayer prepareToPlay];

    [self.view addSubview:videoPlayer.view];

    [videoPlayer play];

    videoPlayer.movieControlMode = MPMovieControlModeHidden;

    // Register to receive a notification when the movie has finished playing.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackComplete:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:videoPlayer];

/* configuring notification*/
- (void)moviePlayBackComplete:(NSNotification *)notification
{
    [videoPlayer stop];
}
于 2012-10-16T18:53:03.527 回答
1

这是我关于用 iPhone 播放.3gp文件的答案.....我已经 使用MpMoviePlayerController成功地用 iphone sdk 播放了 .3gp 文件,我的答案链接是:

链接:https ://stackoverflow.com/a/13088808/1092219

希望你能从我的回答中得到帮助…………!!:))))))

于 2012-10-26T14:32:42.023 回答
1

您需要保留对 moviePlayerController 的引用。它正在被释放并阻止调用任何委托消息。可能最容易放置它的地方是包含- (void)clickplay实现的类中。也就是说,添加一个名为的新实例变量并将moviePlayerController其分配给.MPMoviePlayerControllerclickplay

于 2012-10-16T17:55:32.047 回答