【问题标题】:video takes long time in loading in iphone视频需要很长时间才能在 iphone 中加载
【发布时间】:2011-09-07 09:09:49
【问题描述】:

我正在尝试使用 MPMoviePlayerController 和 NSURL 从服务器播放视频。视频播放完美,但加载需要很多时间。以下是我的代码:

- (void) readyPlayer {
    mp =  [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if ([mp respondsToSelector:@selector(loadState)]) {
        // Set movie player layout
        [mp setControlStyle:MPMovieControlStyleFullscreen];
        [mp setFullscreen:YES];

        // May help to reduce latency
        [mp prepareToPlay];

        // Register that the load state changed (movie is ready)
        [[NSNotificationCenter defaultCenter] addObserver:self           
                                                 selector:@selector(moviePlayerLoadStateChanged:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:nil];
    }

    else{
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinish:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];
    }

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
}



- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {
    [lblActivity removeFromSuperview];
    [activity stopAnimating];
    // Unless state is unknown, start playback
    if ([mp loadState] != MPMovieLoadStateUnknown)
    {
        // Remove observer        
        [[NSNotificationCenter  defaultCenter] 
         removeObserver:self
         name:MPMoviePlayerLoadStateDidChangeNotification 
         object:nil];
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

        // Rotate the view for landscape playback      
        [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
        [[self view] setCenter:CGPointMake(160, 240)];
        [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

        // Set frame of movieplayer
        [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];

        // Add movie player as subview
        [[self view] addSubview:[mp view]];   

        // Play the movie
        [mp play];
    }
}

有人可以帮我弄清楚为什么加载需要这么多时间吗?

谢谢
潘卡伊

【问题讨论】:

    标签: iphone ios4 mpmovieplayercontroller iostream


    【解决方案1】:

    我假设这显然不是您手机上的互联网连接的问题。您是否尝试从您的应用和其他原生应用(例如 YouTube 或 Safari)在手机上加载相同的视频,看看是否有区别?

    查看我们完成的类似代码,我想知道是否需要显式调用[mp prepareToPlay]; 方法。它在调用play 时自动调用,所以我们没有明确这样做。可以不用这个方法试试看有没有区别?

    希望这会有所帮助!

    【讨论】:

    • 您好 Madhumal,感谢您的回复我已按照您的建议删除了 [mp prepareToPlay] 行。但播放视频仍然需要将近 28 秒。我的互联网连接很好,播放流式视频通常不需要太多时间。
    • 嗨 pankaj,只是为了在类似条件下测试它,您是否尝试在同一部手机上(而不是在您的桌面浏览器或其他任何东西上)从 Safari 加载相同的 URL?如果这会导致加载时间明显加快,那么可以肯定地认为这可能是您的应用存在的问题。
    • 28 秒远远超过了常规应用程序/流所需的时间。通常我们会说 3-10 秒。
    猜你喜欢
    • 2012-02-11
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多