无法在iPhone应用中播放来自网址的视频?

时间:2012-10-16 17:38:55

标签: objective-c ios video

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

-(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无效。有人可以帮我解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分: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];
}

答案 2 :(得分:1)

这是我用iPhone播放 .3gp 文件的答案..... 我使用 <成功播放了带有iphone sdk的.3gp文件 em> MpMoviePlayerController ,我的回答链接是:

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

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