在iOS7上播放视频流 [英] Playing a video stream on iOS7
本文介绍了在iOS7上播放视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在iOS上播放简单的直播链接。有一个视图控制器带有一个按钮,其播放动作定义如下。
I'm trying to play a simple live stream link on iOS. There's one view controller with a button with a play action defined as below.
- (IBAction)play:(id)sender {
NSString *path = @"http://asish.flashmediacast.com:2135/live/International/playlist.m3u8";
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
[mp.view setFrame:[self.view bounds]];
[mp prepareToPlay];
[mp play];
}
当按下按钮时没有任何反应。我检查了链接,它工作正常。我哪里错了?
Well nothing happens when the button's pressed. I've checked the link, it works fine. Where'm I going wrong?
我找到了一个解决方案,告诉你创建一个MPMovieViewCOntroller
I found a solution that tells you to create a MPMovieViewCOntroller
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];
问题是如何调用此ViewCOntroller?
Question is how do I call this ViewCOntroller?
推荐答案
看看这个链接。问题不在于URL,它完美地与 MPMoviePlayerViewController
一起玩。
Look at this Link. The Problem is not with URL, its perfectly playing with MPMoviePlayerViewController
.
-(IBAction)btnVideoClicked:(id)sender
{
@try
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
GetVideos *obj_video = [arrVideos objectAtIndex:[sender tag]];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:obj_video.VideoPath]];
[moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayerViewController.moviePlayer setShouldAutoplay:YES];
[moviePlayerViewController.moviePlayer setFullscreen:NO animated:YES];
[moviePlayerViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[moviePlayerViewController.moviePlayer setScalingMode:MPMovieScalingModeNone];
[moviePlayerViewController.moviePlayer setUseApplicationAudioSession:NO];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:moviePlayerViewController];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayerViewController release];
[pool release];
}
@catch (NSException *exception) {
// throws exception
}
}
这篇关于在iOS7上播放视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文