Commit 6df8d96a authored by David Fuhrmann's avatar David Fuhrmann Committed by Jean-Baptiste Kempf

macosx: Fix resume playback in certain situations

For resumption we need to rely on the "time" variable instead of
"position", as the total duration of the file might not have been
set yet.

Also simplifies the code.

close #11981

(cherry picked from commit c91715f76e29b933128f772d3c936c1d2eea8227)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 25febaf4
...@@ -1527,14 +1527,6 @@ ...@@ -1527,14 +1527,6 @@
NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url]; NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
if (lastPosition && lastPosition.intValue > 0) { if (lastPosition && lastPosition.intValue > 0) {
vlc_value_t pos;
var_Get(p_input_thread, "position", &pos);
float f_current_pos = 100. * pos.f_float;
long long int dur = input_item_GetDuration(p_item) / 1000000;
int current_pos_in_sec = (f_current_pos * dur) / 100;
if (current_pos_in_sec >= lastPosition.intValue)
return;
int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback"); int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
NSInteger returnValue = NSAlertErrorReturn; NSInteger returnValue = NSAlertErrorReturn;
...@@ -1550,9 +1542,9 @@ ...@@ -1550,9 +1542,9 @@
if (returnValue == NSAlertAlternateReturn || settingValue == 2) if (returnValue == NSAlertAlternateReturn || settingValue == 2)
lastPosition = [NSNumber numberWithInt:0]; lastPosition = [NSNumber numberWithInt:0];
pos.f_float = (float)lastPosition.intValue / (float)dur; mtime_t lastPos = (mtime_t)lastPosition.intValue * 1000000;
msg_Dbg(VLCIntf, "continuing playback at %2.2f", pos.f_float); msg_Dbg(VLCIntf, "continuing playback at %lld", lastPos);
var_Set(p_input_thread, "position", pos); var_SetTime(p_input_thread, "time", lastPos);
if (returnValue == NSAlertOtherReturn) if (returnValue == NSAlertOtherReturn)
config_PutInt(VLCIntf, "macosx-continue-playback", 1); config_PutInt(VLCIntf, "macosx-continue-playback", 1);
...@@ -1581,15 +1573,14 @@ ...@@ -1581,15 +1573,14 @@
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"recentlyPlayedMedia"]]; NSMutableDictionary *mutDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"recentlyPlayedMedia"]];
vlc_value_t pos; float relativePos = var_GetFloat(p_input_thread, "position");
var_Get(p_input_thread, "position", &pos); mtime_t pos = var_GetTime(p_input_thread, "time") / 1000000;
float f_current_pos = 100. * pos.f_float; mtime_t dur = input_item_GetDuration(p_item) / 1000000;
long long int dur = input_item_GetDuration(p_item) / 1000000;
int current_pos_in_sec = (f_current_pos * dur) / 100;
NSMutableArray *mediaList = [[defaults objectForKey:@"recentlyPlayedMediaList"] mutableCopy]; NSMutableArray *mediaList = [[defaults objectForKey:@"recentlyPlayedMediaList"] mutableCopy];
if (pos.f_float > .05 && pos.f_float < .95 && dur > 180) { if (relativePos > .05 && relativePos < .95 && dur > 180) {
[mutDict setObject:[NSNumber numberWithInt:current_pos_in_sec] forKey:url]; [mutDict setObject:[NSNumber numberWithInt:pos] forKey:url];
[mediaList removeObject:url]; [mediaList removeObject:url];
[mediaList addObject:url]; [mediaList addObject:url];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment