[vlc-devel] commit: macosx/framework: VLCAudio now use a media_player. Cool. (Pierre d' Herbemont )

git version control git at videolan.org
Tue Feb 2 01:42:33 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Tue Feb  2 01:42:00 2010 +0100| [53d2132c974e12f98ff6863ccae27decebb9120f] | committer: Pierre d'Herbemont 

macosx/framework: VLCAudio now use a media_player. Cool.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=53d2132c974e12f98ff6863ccae27decebb9120f
---

 .../framework/Headers/Internal/VLCLibVLCBridging.h |    6 ++--
 .../macosx/framework/Headers/Public/VLCAudio.h     |    6 ++--
 .../framework/Headers/Public/VLCMediaPlayer.h      |    1 +
 projects/macosx/framework/Sources/VLCAudio.m       |   34 ++++++++++++++------
 projects/macosx/framework/Sources/VLCMediaPlayer.m |    5 ++-
 5 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/projects/macosx/framework/Headers/Internal/VLCLibVLCBridging.h b/projects/macosx/framework/Headers/Internal/VLCLibVLCBridging.h
index 3a81579..59efc77 100644
--- a/projects/macosx/framework/Headers/Internal/VLCLibVLCBridging.h
+++ b/projects/macosx/framework/Headers/Internal/VLCLibVLCBridging.h
@@ -147,10 +147,10 @@ extern void __catch_exception( void * e, const char * function, const char * fil
 @interface VLCAudio (VLCAudioBridging)
 /* Initializers */
 /**
- * Initializes a new object using the specified library instance.
- * \return Newly created audio object using specified VLCLibrary instance.
+ * Initializes a new object using the specified mediaPlayer instance.
+ * \return Newly created audio object using specified VLCMediaPlayer instance.
  */
-- (id)initWithLibrary:(VLCLibrary *)library;
+- (id)initWithMediaPlayer:(VLCMediaPlayer *)mediaPlayer;
 @end
 
 /**
diff --git a/projects/macosx/framework/Headers/Public/VLCAudio.h b/projects/macosx/framework/Headers/Public/VLCAudio.h
index 270caee..a44bd38 100644
--- a/projects/macosx/framework/Headers/Public/VLCAudio.h
+++ b/projects/macosx/framework/Headers/Public/VLCAudio.h
@@ -28,14 +28,14 @@
  */
 extern NSString * VLCMediaPlayerVolumeChanged;
 
- at class VLCLibrary;
+ at class VLCMediaPlayer;
 
 /**
  * TODO: Documentation VLCAudio
  */
- at interface VLCAudio : NSObject 
+ at interface VLCAudio : NSObject
 {
-    VLCLibrary * library;   //< Library to control audio for
+    void *instance;
 }
 
 /* Properties */
diff --git a/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h b/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
index bbe0cbd..e3669ea 100644
--- a/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
+++ b/projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
@@ -86,6 +86,7 @@ extern NSString * VLCMediaPlayerStateToString(VLCMediaPlayerState state);
     VLCMediaPlayerState cachedState;    //< Cached state of the media being played
     float position;                     //< The position of the media being played
     id drawable;                        //< The drawable associated to this media player
+    VLCAudio *audio;
 }
 
 /* Initializers */
diff --git a/projects/macosx/framework/Sources/VLCAudio.m b/projects/macosx/framework/Sources/VLCAudio.m
index b1483d2..1844e7e 100644
--- a/projects/macosx/framework/Sources/VLCAudio.m
+++ b/projects/macosx/framework/Sources/VLCAudio.m
@@ -35,31 +35,45 @@ NSString * VLCMediaPlayerVolumeChanged = @"VLCMediaPlayerVolumeChanged";
 /* libvlc event callback */
 // TODO: Callbacks
 
+
 @implementation VLCAudio
+/**
+ * Use this method instead of instance directly as this one is type checked.
+ */
+- (libvlc_media_player_t *)instance
+{
+    return instance;
+}
 
 - (id)init
 {
     return nil;
 }
 
-- (id)initWithLibrary:(VLCLibrary *)aLibrary
+- (id)initWithMediaPlayer:(VLCMediaPlayer *)mediaPlayer
 {
-    if (![library audio] && (self = [super init]))
-    {
-        library = aLibrary;
-        [library setAudio:self];
-    }
+    self = [super init];
+    if (!self)
+        return nil;
+    instance = [mediaPlayer libVLCMediaPlayer];
+    libvlc_media_player_retain([self instance]);
     return self;
 }
 
+- (void) dealloc
+{
+    libvlc_media_player_release([self instance]);
+    [super dealloc];
+}
+
 - (void)setMute:(BOOL)value
 {
-    libvlc_audio_set_mute([library instance], value);
+    libvlc_audio_set_mute([self instance], value);
 }
 
 - (BOOL)isMuted
 {
-    return libvlc_audio_get_mute([library instance]);
+    return libvlc_audio_get_mute([self instance]);
 }
 
 - (void)setVolume:(NSUInteger)value
@@ -68,7 +82,7 @@ NSString * VLCMediaPlayerVolumeChanged = @"VLCMediaPlayerVolumeChanged";
         value = VOLUME_MIN;
     else if (value > VOLUME_MAX)
         value = VOLUME_MAX;
-    libvlc_audio_set_volume([library instance], value);
+    libvlc_audio_set_volume([self instance], value);
 }
 
 - (void)volumeUp
@@ -93,6 +107,6 @@ NSString * VLCMediaPlayerVolumeChanged = @"VLCMediaPlayerVolumeChanged";
 
 - (NSUInteger)volume
 {
-    return libvlc_audio_get_volume([library instance]);
+    return libvlc_audio_get_volume([self instance]);
 }
 @end
diff --git a/projects/macosx/framework/Sources/VLCMediaPlayer.m b/projects/macosx/framework/Sources/VLCMediaPlayer.m
index 2359600..05b641f 100644
--- a/projects/macosx/framework/Sources/VLCMediaPlayer.m
+++ b/projects/macosx/framework/Sources/VLCMediaPlayer.m
@@ -225,6 +225,7 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
     [cachedTime release];
     [cachedRemainingTime release];
     [drawable release];
+    [audio release];
 
     [super dealloc];
 }
@@ -262,7 +263,9 @@ static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * s
 
 - (VLCAudio *)audio
 {
-    return [[VLCLibrary sharedLibrary] audio];
+    if (!audio)
+        audio = [[VLCAudio alloc] initWithMediaPlayer:self];
+    return audio;
 }
 
 #pragma mark -




More information about the vlc-devel mailing list