@@ -156,6 +156,9 @@ class PlayerCore: NSObject {
156
156
/// Whether shutdown of this player has completed (mpv has shutdown).
157
157
var isShutdown = false
158
158
159
+ /// Whether stopping of this player has been initiated.
160
+ var isStopping = false
161
+
159
162
/// Whether mpv playback has stopped and the media has been unloaded.
160
163
var isStopped = true
161
164
@@ -660,6 +663,7 @@ class PlayerCore: NSObject {
660
663
// initiated directly through mpv.
661
664
guard !isStopped else { return }
662
665
Logger . log ( " Stopping playback " , subsystem: subsystem)
666
+ isStopping = true
663
667
mpv. command ( . stop)
664
668
}
665
669
@@ -670,6 +674,7 @@ class PlayerCore: NSObject {
670
674
func playbackStopped( ) {
671
675
Logger . log ( " Playback has stopped " , subsystem: subsystem)
672
676
isStopped = true
677
+ isStopping = false
673
678
postNotification ( . iinaPlayerStopped)
674
679
}
675
680
@@ -1481,6 +1486,7 @@ class PlayerCore: NSObject {
1481
1486
triedUsingExactSeekForCurrentFile = false
1482
1487
info. fileLoading = false
1483
1488
info. haveDownloadedSub = false
1489
+ isStopping = false
1484
1490
isStopped = false
1485
1491
checkUnsyncedWindowOptions ( )
1486
1492
// generate thumbnails if window has loaded video
@@ -1546,8 +1552,10 @@ class PlayerCore: NSObject {
1546
1552
}
1547
1553
1548
1554
func trackListChanged( ) {
1549
- // Must not process track list changes if mpv is terminating.
1550
- guard !isShuttingDown else { return }
1555
+ // No need to process track list changes if playback is being stopped. Must not process track
1556
+ // list changes if mpv is terminating as accessing mpv once shutdown has been initiated can
1557
+ // trigger a crash.
1558
+ guard !isStopping, !isStopped, !isShuttingDown else { return }
1551
1559
Logger . log ( " Track list changed " , subsystem: subsystem)
1552
1560
getTrackInfo ( )
1553
1561
getSelectedTracks ( )
@@ -1578,7 +1586,9 @@ class PlayerCore: NSObject {
1578
1586
func refreshEdrMode( ) {
1579
1587
guard mainWindow. loaded else { return }
1580
1588
DispatchQueue . main. async {
1581
- guard !self . isStopped else { return }
1589
+ // No need to refresh if playback is being stopped. Must not attempt to refresh if mpv is
1590
+ // terminating as accessing mpv once shutdown has been initiated can trigger a crash.
1591
+ guard !self . isStopping, !self . isStopped, !self . isShuttingDown else { return }
1582
1592
self . mainWindow. videoView. refreshEdrMode ( )
1583
1593
}
1584
1594
}
0 commit comments