2012-08-07 114 views
0

我想在iphone应用程序从URL播放视频,但它并没有在应用程序中扮演我用下面的代码如何从HTP网址在iPhone应用程序播放视频

-(IBAction)play 
{ 
    NSString*[email protected]"http://myserver.com.pk/Specticle_Revision_v1.mov"; 
    NSLog(@"Filepath is: %@", videoFilepath); 
    NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath]; 
    MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie]; 
    [movie play]; 
} 
+0

NSURL * videoURL = [NSURL URLWithString:videoFilepath]; – Mani 2012-08-07 09:37:44

回答

1

这样做:

NSURL *url = [NSURL URLWithString:@"http://myserver.com.pk/Specticle_Revision_v1.mov"]; 
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 

[[NSNotificationCenter defaultCenter] addObserver:self 
           selector:@selector(moviePlaybackDidFinish:) 
            name:MPMoviePlayerPlaybackDidFinishNotification 
            object:mp];  

mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 

[self presentMoviePlayerViewControllerAnimated:mp]; 
[mp release]; 
1

如下:

NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath]; 

是你的问题。您的“http://”样式的网址不是文件网址。文件URL(在本地设备/文件系统上)以“file:///”开头。

尝试:

NSURL * videoURL = [NSURL URLWithString: videoFilepath]; 

,看看是否能更好地工作。

相关问题