|
@@ -293,7 +293,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
if (_mediaPlayer.media) {
|
|
if (_mediaPlayer.media) {
|
|
[_mediaPlayer pause];
|
|
[_mediaPlayer pause];
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- [self _savePlaybackState];
|
|
|
|
|
|
+ [_delegate savePlaybackState: self];
|
|
#endif
|
|
#endif
|
|
[_mediaPlayer stop];
|
|
[_mediaPlayer stop];
|
|
}
|
|
}
|
|
@@ -326,94 +326,13 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
|
|
|
|
- (void)restoreAudioAndSubtitleTrack
|
|
- (void)restoreAudioAndSubtitleTrack
|
|
{
|
|
{
|
|
- MLFile *item = [MLFile fileForURL:_mediaPlayer.media.url].firstObject;
|
|
|
|
|
|
+ VLCMLMedia *media = [_delegate mediaForPlayingMedia:_mediaPlayer.media];
|
|
|
|
|
|
- if (item) {
|
|
|
|
- _mediaPlayer.currentAudioTrackIndex = item.lastAudioTrack.intValue;
|
|
|
|
- _mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue;
|
|
|
|
|
|
+ if (media) {
|
|
|
|
+ _mediaPlayer.currentAudioTrackIndex = (int) media.audioTrackIndex;
|
|
|
|
+ _mediaPlayer.currentVideoSubTitleIndex = (int) media.subtitleTrackIndex;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-- (void)_savePlaybackState
|
|
|
|
-{
|
|
|
|
- @try {
|
|
|
|
- [[MLMediaLibrary sharedMediaLibrary] save];
|
|
|
|
- }
|
|
|
|
- @catch (NSException *exception) {
|
|
|
|
- APLog(@"saving playback state failed");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
|
|
|
|
- MLFile *fileItem = files.firstObject;
|
|
|
|
-
|
|
|
|
- if (!fileItem) {
|
|
|
|
- APLog(@"couldn't find file, not saving playback progress");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @try {
|
|
|
|
- float position = _mediaPlayer.position;
|
|
|
|
- fileItem.lastPosition = @(position);
|
|
|
|
- fileItem.lastAudioTrack = @(_mediaPlayer.currentAudioTrackIndex);
|
|
|
|
- fileItem.lastSubtitleTrack = @(_mediaPlayer.currentVideoSubTitleIndex);
|
|
|
|
-
|
|
|
|
- if (position > .95)
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
- if (_mediaPlayer.hasVideoOut) {
|
|
|
|
- NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
- NSString *newThumbnailPath = [searchPaths.firstObject stringByAppendingPathComponent:@"VideoSnapshots"];
|
|
|
|
- NSError *error;
|
|
|
|
-
|
|
|
|
- [[NSFileManager defaultManager] createDirectoryAtPath:newThumbnailPath withIntermediateDirectories:YES attributes:nil error:&error];
|
|
|
|
- if (error == nil) {
|
|
|
|
- newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
|
|
|
|
- [_mediaPlayer saveVideoSnapshotAt:newThumbnailPath withWidth:0 andHeight:0];
|
|
|
|
- _recheckForExistingThumbnail = YES;
|
|
|
|
- [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:.25];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- @catch (NSException *exception) {
|
|
|
|
- APLog(@"failed to save current media state - file removed?");
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#if TARGET_OS_IOS
|
|
|
|
-- (void)_updateStoredThumbnailForFile:(MLFile *)fileItem
|
|
|
|
-{
|
|
|
|
- NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
|
|
- NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
- NSString* newThumbnailPath = [searchPaths[0] stringByAppendingPathComponent:@"VideoSnapshots"];
|
|
|
|
- newThumbnailPath = [newThumbnailPath stringByAppendingPathComponent:fileItem.objectID.URIRepresentation.lastPathComponent];
|
|
|
|
-
|
|
|
|
- if (![fileManager fileExistsAtPath:newThumbnailPath]) {
|
|
|
|
- if (_recheckForExistingThumbnail) {
|
|
|
|
- [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
|
|
|
|
- _recheckForExistingThumbnail = NO;
|
|
|
|
- } else
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- UIImage *newThumbnail = [UIImage imageWithContentsOfFile:newThumbnailPath];
|
|
|
|
- if (!newThumbnail) {
|
|
|
|
- if (_recheckForExistingThumbnail) {
|
|
|
|
- [self performSelector:@selector(_updateStoredThumbnailForFile:) withObject:fileItem afterDelay:1.];
|
|
|
|
- _recheckForExistingThumbnail = NO;
|
|
|
|
- } else
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @try {
|
|
|
|
- [fileItem setComputedThumbnailScaledForDevice:newThumbnail];
|
|
|
|
- }
|
|
|
|
- @catch (NSException *exception) {
|
|
|
|
- APLog(@"updating thumbnail failed");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- [fileManager removeItemAtPath:newThumbnailPath error:nil];
|
|
|
|
-}
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
|
@@ -422,9 +341,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
_mediaWasJustStarted = NO;
|
|
_mediaWasJustStarted = NO;
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
if (self.mediaList) {
|
|
if (self.mediaList) {
|
|
- NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
|
|
|
|
- MLFile *item = matches.firstObject;
|
|
|
|
- [self _recoverLastPlaybackStateOfItem:item];
|
|
|
|
|
|
+ [self _recoverLastPlaybackState];
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
@@ -756,11 +673,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
} break;
|
|
} break;
|
|
- case VLCMediaPlayerStateESAdded: {
|
|
|
|
-#if TARGET_OS_IOS
|
|
|
|
- [self restoreAudioAndSubtitleTrack];
|
|
|
|
-#endif
|
|
|
|
- } break;
|
|
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -791,7 +703,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
{
|
|
{
|
|
[_listPlayer pause];
|
|
[_listPlayer pause];
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- [self _savePlaybackState];
|
|
|
|
|
|
+ [_delegate savePlaybackState: self];
|
|
#endif
|
|
#endif
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
|
|
}
|
|
}
|
|
@@ -1131,7 +1043,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
APLog(@"Pausing playback as previously connected external audio playback device was removed");
|
|
APLog(@"Pausing playback as previously connected external audio playback device was removed");
|
|
[_mediaPlayer pause];
|
|
[_mediaPlayer pause];
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- [self _savePlaybackState];
|
|
|
|
|
|
+ [_delegate savePlaybackState: self];
|
|
#endif
|
|
#endif
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
|
|
}
|
|
}
|
|
@@ -1173,46 +1085,40 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
}
|
|
}
|
|
|
|
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
-- (void)_recoverLastPlaybackStateOfItem:(MLFile *)item
|
|
|
|
-{
|
|
|
|
- if (item) {
|
|
|
|
- CGFloat lastPosition = .0;
|
|
|
|
- NSInteger duration = 0;
|
|
|
|
-
|
|
|
|
- if (item.lastPosition) {
|
|
|
|
- lastPosition = item.lastPosition.floatValue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- duration = item.duration.intValue;
|
|
|
|
-
|
|
|
|
- if (lastPosition < .95 && _mediaPlayer.position < lastPosition) {
|
|
|
|
- NSInteger continuePlayback;
|
|
|
|
- if ([item isAlbumTrack] || [item isSupportedAudioFile])
|
|
|
|
- continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioPlayback] integerValue];
|
|
|
|
- else
|
|
|
|
- continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinuePlayback] integerValue];
|
|
|
|
-
|
|
|
|
- if (continuePlayback == 1) {
|
|
|
|
- [self setPlaybackPosition:lastPosition];
|
|
|
|
- } else if (continuePlayback == 0) {
|
|
|
|
- NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
|
|
|
|
- style: UIAlertActionStyleCancel
|
|
|
|
- action: nil],
|
|
|
|
- [[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
|
|
|
|
- action: ^(UIAlertAction *action) {
|
|
|
|
- [self setPlaybackPosition:lastPosition];
|
|
|
|
- }]
|
|
|
|
- ];
|
|
|
|
- UIViewController *presentingVC = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
|
|
- presentingVC = presentingVC.presentedViewController ?: presentingVC;
|
|
|
|
- [VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"CONTINUE_PLAYBACK", nil)
|
|
|
|
- errorMessage:[NSString stringWithFormat:NSLocalizedString(@"CONTINUE_PLAYBACK_LONG", nil), item.title]
|
|
|
|
- viewController:presentingVC
|
|
|
|
- buttonsAction:buttonsAction];
|
|
|
|
|
|
+- (void)_recoverLastPlaybackState
|
|
|
|
+{
|
|
|
|
+ VLCMLMedia *media = [_delegate mediaForPlayingMedia:_mediaPlayer.media];
|
|
|
|
+ if (!media) return;
|
|
|
|
+
|
|
|
|
+ CGFloat lastPosition = media.progress;
|
|
|
|
+ if (_mediaPlayer.position < lastPosition) {
|
|
|
|
+ NSInteger continuePlayback;
|
|
|
|
+ if (media.type == VLCMLMediaTypeAudio)
|
|
|
|
+ continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioPlayback] integerValue];
|
|
|
|
+ else
|
|
|
|
+ continuePlayback = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinuePlayback] integerValue];
|
|
|
|
+
|
|
|
|
+ if (continuePlayback == 1) {
|
|
|
|
+ [self setPlaybackPosition:lastPosition];
|
|
|
|
+ } else if (continuePlayback == 0) {
|
|
|
|
+ NSArray<VLCAlertButton *> *buttonsAction = @[[[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CANCEL", nil)
|
|
|
|
+ style: UIAlertActionStyleCancel
|
|
|
|
+ action: nil],
|
|
|
|
+ [[VLCAlertButton alloc] initWithTitle: NSLocalizedString(@"BUTTON_CONTINUE", nil)
|
|
|
|
+ action: ^(UIAlertAction *action) {
|
|
|
|
+ [self setPlaybackPosition:lastPosition];
|
|
|
|
+ }]
|
|
|
|
+ ];
|
|
|
|
+ UIViewController *presentingVC = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
|
|
+ presentingVC = presentingVC.presentedViewController ?: presentingVC;
|
|
|
|
+ [VLCAlertViewController alertViewManagerWithTitle:NSLocalizedString(@"CONTINUE_PLAYBACK", nil)
|
|
|
|
+ errorMessage:[NSString stringWithFormat:NSLocalizedString(@"CONTINUE_PLAYBACK_LONG", nil), media.title]
|
|
|
|
+ viewController:presentingVC
|
|
|
|
+ buttonsAction:buttonsAction];
|
|
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ [self restoreAudioAndSubtitleTrack];
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -1253,7 +1159,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
|
|
- (void)applicationWillResignActive:(NSNotification *)aNotification
|
|
- (void)applicationWillResignActive:(NSNotification *)aNotification
|
|
{
|
|
{
|
|
#if TARGET_OS_IOS
|
|
#if TARGET_OS_IOS
|
|
- [self _savePlaybackState];
|
|
|
|
|
|
+ [_delegate savePlaybackState: self];
|
|
#endif
|
|
#endif
|
|
if (![self isPlayingOnExternalScreen]
|
|
if (![self isPlayingOnExternalScreen]
|
|
&& ![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioInBackgroundKey] boolValue]) {
|
|
&& ![[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingContinueAudioInBackgroundKey] boolValue]) {
|