基本上,我从网络服务器获取网址。我想在iPhone应用中播放该网址的电影文件。请帮忙!我的意思是说我的电影文件存储在网络服务器上
答案 0 :(得分:9)
这是从服务器或本地路径播放视频文件的常用方法。
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[[player view] setFrame: [myView bounds]]; // frame must match parent view
[myView addSubview: [player view]];
[player play];
您可以使用html5的视频标签(假设您使用的是UIWebView)。
- (void)viewDidLoad {
[super viewDidLoad];
//to play from actual server location
//[self playVideo:@"file://localhost/Users/PlayVideos/3idiots.mov" frame:CGRectMake(20, 70, 280, 250)];
//from server (http://www.example.com/video.mov)..... http://www.ebookfrenzy.com/ios_book/movie/movie.mov
[self playVideo:@"your server URL" frame:CGRectMake(20, 70, 280, 250)];
}
- (void)playVideo:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
<script>\
function load(){document.getElementById(\"yt\").play();}\
</script>\
</head><body onload=\"load()\"style=\"margin:0\">\
<video id=\"yt\" src=\"%@\" \
width=\"%0.0f\" height=\"%0.0f\" autoplay controls></video>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
NSLog(@"%@",html);
}
答案 1 :(得分:2)
通过网址从网址投放视频
viewDidLoad{
movieURL=[NSURL URLWithString:@"http://www.samkeeneinteractivedesign.com/videos/littleVid3.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if ([moviePlayer respondsToSelector:@selector(loadState)])
{
// Set movie player layout
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES];
// moviePlayer.view.frame = CGRectMake(10,10,1024,760);
// May help to reduce latency
[moviePlayer prepareToPlay];
}
}