【问题标题】:iOS > possible play a partially downloaded video?iOS > 可能播放部分下载的视频?
【发布时间】:2012-07-03 06:46:43
【问题描述】:

假设我们正在下载一个大视频 - 它的大小为 50Mb - 但到目前为止只下载了 25Mb - 是否可以在视频完全下载之前开始播放?

【问题讨论】:

    标签: ios video asihttprequest


    【解决方案1】:

    我假设您正在为您的视频使用 MPMoviePlayerController...

    MPMoviePlayerController 有一个 loadState 属性,您可以使用this notification 对其进行监控。检查视频是否已下载到可播放范围,然后播放。

    //Begin observing the moviePlayer's load state.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];
    
    
    - (void)moviePlayerLoadStateChanged:(NSNotification *)notification{
        //NSLog(@"State changed to: %d\n", moviePlayer.loadState);
        if(moviePlayer.loadState == MPMovieLoadStatePlayable && [videoIndicator isAnimating]){
            //if load state is ready to play
            [videoIndicator stopAnimating];//Pause and hide the indicator
            [self.contentView addSubview:[moviePlayer view]];
            [moviePlayer setFullscreen:YES animated:YES];
            [moviePlayer play];//play the video
        }
    
    }
    

    这非常重要:如果您尝试下载超过 10 分钟的视频,则需要使用 HTTP Live Streaming

    【讨论】:

    • 我正在使用 ASIHTTPRequest 加载视频,而不是使用 MPMoviePlayerController。是否可以开始播放直到它完全加载?
    • 嗯,我对 ASIHTTPRequest 没有任何经验。我会做一些搜索,但我不能保证我会找到你还没有找到的任何东西。
    猜你喜欢
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 2021-12-18
    • 2020-04-08
    相关资源
    最近更新 更多