@@ -4,6 +4,7 @@ var deepFreeze = require('deep-freeze');
44var ERROR = require ( '../error' ) ;
55
66var SUBS_SCALE_FACTOR = 0.0066 ;
7+ var EOF_END_TOLERANCE = 60000 ;
78
89var stremioToMPVProps = {
910 'loaded' : 'loaded' ,
@@ -259,7 +260,9 @@ function ShellVideo(options) {
259260 ipc . on ( 'mpv-event-ended' , function ( args ) {
260261 // older shells report 'other' for every non-error reason, including eof
261262 if ( args . error ) onError ( args . error ) ;
262- else if ( ! args . reason || args . reason === 'eof' || args . reason === 'other' ) onEnded ( ) ;
263+ else if ( ! args . reason || args . reason === 'eof' || args . reason === 'other' ) {
264+ if ( ! isKnownEarlyEof ( ) ) onEnded ( ) ;
265+ }
263266 } ) ;
264267
265268 function getProp ( propName ) {
@@ -279,6 +282,15 @@ function ShellVideo(options) {
279282 function onEnded ( ) {
280283 events . emit ( 'ended' ) ;
281284 }
285+ function isKnownEarlyEof ( ) {
286+ var time = props [ 'time-pos' ] ;
287+ var duration = props . duration ;
288+ return typeof time === 'number' &&
289+ isFinite ( time ) &&
290+ typeof duration === 'number' &&
291+ isFinite ( duration ) &&
292+ time + EOF_END_TOLERANCE < duration ;
293+ }
282294 function onPropChanged ( propName ) {
283295 if ( observedProps [ propName ] ) {
284296 events . emit ( 'propChanged' , propName , getProp ( propName ) ) ;
0 commit comments