直播视频流iphone

时间:2009-09-29 10:05:01

标签: iphone video-streaming

我是iphone和Objective-c的新手。 我想向使用我的应用的用户展示一场直播比赛,假设足球比赛。 我在iPhone应用程序中的实时视频流需要什么?

对此的任何信息表示赞赏!

由于

伙计们请帮助任何人以前必须这样做吗?

3 个答案:

答案 0 :(得分:3)

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

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

您需要拥有MPMoviePlayerController的对象,其余代码如下:

-(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];
}

答案 1 :(得分:1)

假设您拥有相关足球比赛的视频权利,您需要一个编码器,它将实时视频编码,动态播放到正确的格式(mp4,h263等)。 iPhone播放这些播放器的方法是拥有一个动态播放列表,该播放列表将通过实时视频的块来播放它。

答案 2 :(得分:1)