设置 initialPlaybackTime 属性后,视频(HTTP 流)仍然从头开始播放。
相同的代码在 iOS <= 8.3 中运行良好:
self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];
设置 initialPlaybackTime 属性后,视频(HTTP 流)仍然从头开始播放。
相同的代码在 iOS <= 8.3 中运行良好:
self.moviePlayer.initialPlaybackTime = self.lastPlaybackTime;
[self.moviePlayer play];
这对我有用,基本上你需要在电影开始播放时设置CurrentPlaybackTime,但是你还需要一个标志playbackDurationSet ,当你展示movieplayer时它设置为NO,当电影第一次被寻找到playbackDuration时它设置为YES .
注意:此标志是必需的,因为当您从搜索擦除器中搜索电影时,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;
}
我也看到了其中一些问题。由于 MPMoviePlayerController 在 iOS 9 中已被弃用,因此它们不太可能被修复。
哈里萨曼回答对我有用:
- (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;
}
//...
}
方法是_iOSatLeast84:
- (BOOL)is_iOSatLeast84
{
// version 8.4
NSString *version = [[UIDevice currentDevice] systemVersion];
BOOL isAtLeast84 = [version floatValue] >= 8.35;
return isAtLeast84;
}
尽管所有这些都是一种解决方法,但它可以完成工作。