0
MPMoviePlayerController 및 NSURL을 사용하여 서버에서 비디오를 재생하려고합니다. 동영상은 완벽하게 재생되지만로드하는 데 시간이 오래 걸립니다. 다음은 내 코드입니다.iphone에 비디오를로드하는 데 비디오 시간이 오래 걸림.
- (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];
}
}
로드 중 왜 많은 시간이 걸리는지 알 수 있습니까?
감사
판 카지
안녕하세요 Madhumal, 답장을 보내 주셔서 감사합니다. 귀하의 제안을 따르고 [mp prepareToPlay] 행을 삭제했습니다. 그러나 비디오 재생에서 여전히 28 초 가까이 걸렸습니다. 인터넷 연결 상태가 좋으며 일반적으로 스트리밍 된 비디오를 재생할 때 너무 많은 시간이 걸리지 않습니다. – pankaj
안녕하세요 pankaj, 비슷한 조건에서 테스트하기 위해 Safari에서 동일한 URL (데스크탑 브라우저가 아닌)을로드하려고 시도 했습니까? 이로 인해로드 시간이 눈에 띄게 빨라지므로이 문제가 앱에 문제가 있다고 가정하는 것이 안전합니다. – Madhu
28 초는 일반적인 앱/스트림에 비해 훨씬 큽니다. 보통 우리는 3-10 초를 말하고 있습니다. – Till