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 )
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];
+
}
- (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
- (void)mediaPlayerPositionChanged:(NSNumber *)newTime;
- (void)mediaPlayerStateChanged:(NSNumber *)newState;
+- (void)mediaPlayerMediaChanged:(VLCMedia *)media;
@end
@implementation VLCMediaPlayer
/* 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 );
}
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
[self didChangeValueForKey:@"state"];
}
+- (void)mediaPlayerMediaChanged:(VLCMedia *)newMedia
+{
+ [self willChangeValueForKey:@"media"];
+ if (media != newMedia)
+ {
+ [media release];
+ media = [newMedia retain];
+ }
+ [self didChangeValueForKey:@"media"];
+}
+
@end