]> git.sesse.net Git - vlc/blobdiff - projects/macosx/framework/Sources/VLCMediaPlayer.m
osx/framework: extended API to cover titles, fps, playback modes and some convienienc...
[vlc] / projects / macosx / framework / Sources / VLCMediaPlayer.m
index 4954260400721a8c58c3e4069f80b4e3055e8886..662e35e137acc0e1c93dece0c6332e792b476237 100644 (file)
@@ -1,12 +1,14 @@
 /*****************************************************************************
  * VLCMediaPlayer.m: VLCKit.framework VLCMediaPlayer implementation
  *****************************************************************************
- * Copyright (C) 2007 Pierre d'Herbemont
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007-2009 Pierre d'Herbemont
+ * Copyright (C) 2007-2009 the VideoLAN team
+ * Partial Copyright (C) 2009 Felix Paul Kühne
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  *          Faustion Osuna <enrique.osuna # gmail.com>
+ *          Felix Paul Kühne <fkuehne # videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -192,15 +194,23 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void *
 
 - (void)dealloc
 {
+    NSAssert(libvlc_media_player_get_state(instance, NULL) == libvlc_Stopped, @"You released the media player before ensuring that it is stopped");
+
     // Always get rid of the delegate first so we can stop sending messages to it
     // TODO: Should we tell the delegate that we're shutting down?
     delegate = nil;
 
-    libvlc_media_player_release((libvlc_media_player_t *)instance);
+    // Clear our drawable as we are going to release it, we don't
+    // want the core to use it from this point. This won't happen as
+    // the media player must be stopped.
+    libvlc_media_player_set_nsobject(instance, nil, NULL);
+
+    libvlc_media_player_release(instance);
     
     // Get rid of everything else
     [media release];
     [cachedTime release];
+    [drawable release];
 
     [super dealloc];
 }
@@ -391,9 +401,21 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void *
     return [VLCTime timeWithNumber:[NSNumber numberWithDouble:-remaining]];
 }
 
+- (int)fps
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    int result = libvlc_media_player_get_fps( instance, &ex );
+    catch_exception( &ex );
+    return result;
+}
+
 - (void)setChapter:(int)value;
 {
-    libvlc_media_player_set_chapter( instance, value, NULL );
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    libvlc_media_player_set_chapter( instance, value, &ex );
+    catch_exception( &ex );
 }
 
 - (int)chapter
@@ -414,6 +436,48 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void *
     return result;
 }
 
+- (void)nextChapter
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    libvlc_media_player_next_chapter( instance, &ex );
+    catch_exception( &ex );
+}
+
+- (void)previousChapter
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    libvlc_media_player_previous_chapter( instance, &ex );
+    catch_exception( &ex );
+}
+
+- (void)setTitle:(int)value
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    libvlc_media_player_set_title( instance, value, &ex );
+    catch_exception( &ex );
+}
+
+- (int)title
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    int result = libvlc_media_player_get_title( instance, &ex );
+    catch_exception( &ex );
+    return result;
+}
+
+- (int)countOfTitles
+{
+    libvlc_exception_t ex;
+    libvlc_exception_init( &ex );
+    int result = libvlc_media_player_get_title_count( instance, &ex );
+    catch_exception( &ex );
+    return result;
+}
+
 - (void)setAudioTrack:(int)value
 {
     libvlc_audio_set_track( instance, value, NULL );
@@ -503,16 +567,6 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void *
 
 - (void)stop
 {
-    if( 0 && [NSThread isMainThread] )
-    {
-        /* Hack because we create a dead lock here, when the vout is stopped
-         * and tries to recontact us on the main thread */
-        /* FIXME: to do this properly we need to do some locking. We may want 
-         * to move that to libvlc */
-        [self performSelectorInBackground:@selector(stop) withObject:nil];
-        return;
-    }
-    
     libvlc_exception_t ex;
     libvlc_exception_init( &ex );
     libvlc_media_player_stop((libvlc_media_player_t *)instance, &ex);