我想在iphone应用程序中播放来自url的视频,但它在应用程序中不播放,我使用以下代码
-(IBAction)play
{
NSString*videoFilepath=@"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];
}
这样做:
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];
看起来像这样:
NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];
是你的问题。您的"http://"样式URL不是文件URL。文件URL(在本地设备/文件系统上)以"file:///
"开头。
尝试:
NSURL * videoURL = [NSURL URLWithString: videoFilepath];
看看效果是否更好。