]> git.sesse.net Git - vlc/commitdiff
macosx/framework: VLCAudio now use a media_player. Cool.
authorPierre d'Herbemont <pdherbemont@free.fr>
Tue, 2 Feb 2010 00:42:00 +0000 (01:42 +0100)
committerPierre d'Herbemont <pdherbemont@free.fr>
Tue, 2 Feb 2010 00:42:00 +0000 (01:42 +0100)
projects/macosx/framework/Headers/Internal/VLCLibVLCBridging.h
projects/macosx/framework/Headers/Public/VLCAudio.h
projects/macosx/framework/Headers/Public/VLCMediaPlayer.h
projects/macosx/framework/Sources/VLCAudio.m
projects/macosx/framework/Sources/VLCMediaPlayer.m

index 3a815793d31c4f151823b9406d8cc93000e71112..59efc7757b30bd00ca486db2526fca93def7bf19 100644 (file)
@@ -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
 
 /**
index 270caee5c76faf4332e8462e24c472a7c5568e54..a44bd387a63175d79dd2b864ccb1b14c861ef642 100644 (file)
  */
 extern NSString * VLCMediaPlayerVolumeChanged;
 
-@class VLCLibrary;
+@class VLCMediaPlayer;
 
 /**
  * TODO: Documentation VLCAudio
  */
-@interface VLCAudio : NSObject 
+@interface VLCAudio : NSObject
 {
-    VLCLibrary * library;   //< Library to control audio for
+    void *instance;
 }
 
 /* Properties */
index bbe0cbd81ab5f766558fa4e9ec383f893fbac9c3..e3669eac2accd99777256c4b0cd0a663668f0868 100644 (file)
@@ -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 */
index b1483d2f7425a64718d66b730f0cfb64fdba568d..1844e7ee3b8d41a3e67a2d582e3fd9e1829a4608 100644 (file)
@@ -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
index 2359600a22c7849144d1efc153b684acb13994e3..05b641fa8fb86b434fb9a766e402612ccae4769c 100644 (file)
@@ -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 -