From: Pierre d'Herbemont Date: Tue, 22 Dec 2009 19:50:14 +0000 (+0100) Subject: macosx/framework: Handle media changed events. X-Git-Tag: 1.1.0-ff~1777 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=549b9331e876edcbaf91b75a4388cd4054b8f011;p=vlc macosx/framework: Handle media changed events. --- diff --git a/projects/macosx/framework/Sources/VLCMediaPlayer.m b/projects/macosx/framework/Sources/VLCMediaPlayer.m index e66efe1155..d94ef564ee 100644 --- a/projects/macosx/framework/Sources/VLCMediaPlayer.m +++ b/projects/macosx/framework/Sources/VLCMediaPlayer.m @@ -95,7 +95,7 @@ static void HandleMediaPositionChanged(const libvlc_event_t * event, void * self static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * self) { VLCMediaPlayerState newState; - + if( event->type == libvlc_MediaPlayerPlaying ) newState = VLCMediaPlayerStatePlaying; else if( event->type == libvlc_MediaPlayerPaused ) @@ -109,19 +109,31 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * NSLog(@"%s: Unknown event", __FUNCTION__); return; } - + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - + [[VLCEventManager sharedManager] callOnMainThreadObject:self withMethod:@selector(mediaPlayerStateChanged:) withArgumentAsObject:[NSNumber numberWithInt:newState]]; - + [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self withDelegateMethod:@selector(mediaPlayerStateChanged:) withNotificationName:VLCMediaPlayerStateChanged]; - + [pool release]; + +} +static void HandleMediaPlayerMediaChanged(const libvlc_event_t * event, void * self) +{ + NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; + + [[VLCEventManager sharedManager] callOnMainThreadObject:self + withMethod:@selector(mediaPlayerMediaChanged:) + withArgumentAsObject:[VLCMedia mediaWithLibVLCMediaDescriptor:event->u.media_player_media_changed.new_media]]; + + [pool release]; + } @@ -134,6 +146,7 @@ static void HandleMediaInstanceStateChanged(const libvlc_event_t * event, void * - (void)mediaPlayerTimeChanged:(NSNumber *)newTime; - (void)mediaPlayerPositionChanged:(NSNumber *)newTime; - (void)mediaPlayerStateChanged:(NSNumber *)newState; +- (void)mediaPlayerMediaChanged:(VLCMedia *)media; @end @implementation VLCMediaPlayer @@ -894,6 +907,7 @@ static const VLCMediaPlayerState libvlc_to_local_state[] = /* FIXME: We may want to turn that off when none is interested by that */ libvlc_event_attach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, &ex ); libvlc_event_attach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, &ex ); + libvlc_event_attach( p_em, libvlc_MediaPlayerMediaChanged, HandleMediaPlayerMediaChanged, self, &ex ); catch_exception( &ex ); } @@ -906,6 +920,7 @@ static const VLCMediaPlayerState libvlc_to_local_state[] = libvlc_event_detach( p_em, libvlc_MediaPlayerEndReached, HandleMediaInstanceStateChanged, self, NULL ); libvlc_event_detach( p_em, libvlc_MediaPlayerPositionChanged, HandleMediaPositionChanged, self, NULL ); libvlc_event_detach( p_em, libvlc_MediaPlayerTimeChanged, HandleMediaTimeChanged, self, NULL ); + libvlc_event_attach( p_em, libvlc_MediaPlayerMediaChanged, HandleMediaPlayerMediaChanged, self, NULL ); } - (void)mediaPlayerTimeChanged:(NSNumber *)newTime @@ -941,4 +956,15 @@ static const VLCMediaPlayerState libvlc_to_local_state[] = [self didChangeValueForKey:@"state"]; } +- (void)mediaPlayerMediaChanged:(VLCMedia *)newMedia +{ + [self willChangeValueForKey:@"media"]; + if (media != newMedia) + { + [media release]; + media = [newMedia retain]; + } + [self didChangeValueForKey:@"media"]; +} + @end