gpt4 book ai didi

ios - 在 iOS7 上播放视频流

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:50 25 4
gpt4 key购买 nike

我正在尝试在 iOS 上播放一个简单的直播链接。有一个带有按钮的 View Controller ,其播放 Action 定义如下。

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

好吧,按下按钮时什么也没有发生。我检查了链接,它工作正常。我哪里出错了?

我找到了一个解决方案,告诉您创建一个 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?

最佳答案

看看这个Link .问题不在于 URL,它与 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
    }
}

关于ios - 在 iOS7 上播放视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com