[vlc-devel] [patch] Mac/iOS VLCKit fixes to VLCMediaPlayer dealloc method

Florent Pillet fpillet at gmail.com
Thu Apr 17 11:43:18 CEST 2014

Two fixes here:

- if the stream hasn't been stopped by the time dealloc is called, stopping it is useless because dealloc will most likely occur on the main thread, and the [stop] method executes asynchronously on a background thread. This is a hopeless situation. A dispatch_sync() could be used but since it could cause a deadlock, it's better to have the developer properly stop the stream before disposing of the player.

- if a stream has completely failed to start (i.e. forbidden RTSP access), the player's state is libvlc_NothingSpecial. Handle this case in the debug assert.


diff --git a/Sources/VLCMediaPlayer.m b/Sources/VLCMediaPlayer.m
index e5a32ac..9e4326a 100644
--- a/Sources/VLCMediaPlayer.m
+++ b/Sources/VLCMediaPlayer.m
@@ -221,10 +221,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 - (void)dealloc
-    if (libvlc_media_player_get_state(_playerInstance) != libvlc_Stopped)
-        [self stop];
-    NSAssert(libvlc_media_player_get_state(_playerInstance) == libvlc_Stopped, @"You released the media player before ensuring that it is stopped");
+    NSAssert(libvlc_media_player_get_state(_playerInstance) == libvlc_Stopped || libvlc_media_player_get_state(_playerInstance) == libvlc_NothingSpecial, @"You released the media player before ensuring that it is stopped");
     [self unregisterObservers];
     [[VLCEventManager sharedManager] cancelCallToObject:self];

More information about the vlc-devel mailing list