设置initialPlaybackTime属性后,视频(HTTP流)仍然从头开始播放。
相同的代码在iOS< = 8.3:
中运行良好 self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];
答案 0 :(得分:6)
这对我有用,基本上你需要在电影开始播放时 setCurrentPlaybackTime ,但你还需要一个标志 playbackDurationSet ,当你呈现电影播放器时它被设置为NO当电影第一次被设置为playbackDuration时,它被设置为YES。
注意:此标志是必需的,因为当您从搜索清理器中搜索电影时,将使用playbackState触发 moviePlayerPlaybackStateChanged 的 MPMoviePlaybackStatePlaying 强>
BOOL playbackDurationSet = NO;
- (void)moviePlayerPlaybackStateChanged:(NSNotification*)notification
{
MPMoviePlayerController* player = (MPMoviePlayerController*)notification.object;
switch ( player.playbackState ) {
case MPMoviePlaybackStatePlaying:
if(!playbackDurationSet){
[self.moviePlayer setCurrentPlaybackTime:yourStartTime];
playbackDurationSet = YES;
}
break;
}
}
- (void)moviePlayerPresented
{
playbackDurationSet = NO;
}
答案 1 :(得分:0)
我也看到了其中的一些问题。由于MPMoviePlayerController在iOS 9中已弃用,因此不太可能修复它们。
答案 2 :(得分:0)
- (void)moviePlaybackStateChanged:(NSNotification*)notif
{
//...
if (self.videoPlayer.playbackState == MPMoviePlaybackStatePlaying) {
if (self.currentBookmark) {
if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
[self.videoPlayer setCurrentPlaybackTime:toTime];
self.currentBookmark = nil;
}
}
}
if (self.videoPlayer.playbackState == MPMoviePlaybackStatePaused) {
//...
}
if (self.videoPlayer.playbackState == MPMoviePlaybackStateStopped) {
//...
}
}
也:
- (void)configureMoviePlayer
{
if (self.currentBookmark) {
if ([[PSDeviceInfo sharedInstance] is_iOSatLeast84]){
// will set start after did start
}else {
NSTimeInterval toTime = [self.currentBookmark.seconds doubleValue];
self.videoPlayer.initialPlaybackTime = toTime;
self.currentBookmark = nil;
}
}
else {
self.videoPlayer.initialPlaybackTime = 0;
}
//...
}
方法is_iOSatLeast84:
- (BOOL)is_iOSatLeast84
{
// version 8.4
NSString *version = [[UIDevice currentDevice] systemVersion];
BOOL isAtLeast84 = [version floatValue] >= 8.35;
return isAtLeast84;
}
尽管所有这些都是一种解决方法,但它可以完成工作。