且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

直播视频流iphone

更新时间:2023-01-13 17:40:13

您只需要提供电影文件的URL,然后将根据连接速度自动设置流。

You only need to give the URL of the movie file and the streams will automatically be setup according to the speed of your connection.

请注意,只有那些分辨率在iPhone范围内的视频才能播放。较高分辨率的电影将在模拟器上播放,但不适用于iPhone。

Mind you, only those videos whose resolution is within iPhone's limits will get played. Higher resolution movies will get played on Simulator but will not work on iPhone.

你需要一个 MPMoviePlayerController 的对象,其余代码是这样的:

You need to have an object of MPMoviePlayerController and the rest of the code is like this:

-(void) play {

NSURL *movieURL = [NSURL URLWithString:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"];


if (movieURL != nil) {
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    moviePlayer.initialPlaybackTime = -1.0;

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerScalingModeDidChangeNotification 
                                               object:moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(endPlay:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:moviePlayer];

    moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    moviePlayer.movieControlMode = MPMovieControlModeDefault;
    moviePlayer.backgroundColor = [UIColor blackColor];

    [moviePlayer play];
 }
}

-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
self.navigationItem.hidesBackButton = FALSE;
moviePlayer = [notification object];
[moviePlayer play];
}

-(void)endPlay: (NSNotification*)notification
{
NSLog(@"end Playing");

self.navigationItem.hidesBackButton = FALSE;
//[[UIApplication sharedApplication] endIgnoringInteractionEvents];
[actview stopAnimating];

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerScalingModeDidChangeNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];

[moviePlayer stop];
[moviePlayer release];
}