0

我想在 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];
}
4

2 回答 2

1

Looks like this:

NSURL *videoURL = [NSURL fileURLWithPath:videoFilepath];

Is your problem. Your "http://" - style URL is not a file URL. File URL's (on the local device / file system) begin with "file:///".

Try:

NSURL * videoURL = [NSURL URLWithString: videoFilepath];

and see if that works better.

于 2012-08-07T09:35:31.690 回答
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];
于 2012-08-07T09:41:05.527 回答