我想在iphone app中播放来自网址的视频,但是我在使用以下代码的应用中无法播放
-(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];
}
答案 0 :(得分:1)
看起来像这样:
NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];
你的问题。您的“http://”样式网址不是文件网址。文件URL(在本地设备/文件系统上)以“file:///
”开头。
尝试:
NSURL * videoURL = [NSURL URLWithString: videoFilepath];
看看它是否更好。
答案 1 :(得分: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];