0

我需要在我的应用中播放视频 我能做什么?谢谢。 *这是我的代码。*

#import <MediaPlayer/MediaPlayer.h>
 NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];

       MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [moviePlayerController.view setFrame:CGRectMake(0, 0, 320, 270)];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;
        [moviePlayerController play];
4

2 回答 2

1

由于您尝试从 URL 播放视频,因此您可以使用 WebView 播放它。这是一些示例代码(已测试!):

 NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];

NSURLRequest* requestUrl = [[NSURLRequest alloc] initWithURL:fileURL];

UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];
[self.view addSubview:webView];
[webView loadRequest:requestUrl];
于 2013-11-14T17:06:55.227 回答
1

添加属性:

 @property (nonatomic,strong) MPMoviePlayerController *moviePlayerController;

并将您的代码更改为:

NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[_moviePlayerController.view setFrame:CGRectMake(0, 0, 320, 270)];
[self.view addSubview:_moviePlayerController.view];
_moviePlayerController.fullscreen = YES;
[_moviePlayerController play];

或使用以下代码:

NSURL *movieURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
MPMoviePlayerViewController *movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:movieController];
[movieController.moviePlayer play];
于 2013-11-14T17:16:00.697 回答