static void HandleMediaTimeChanged(const libvlc_event_t * event, void * self)
{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ [[VLCEventManager sharedManager] callOnMainThreadObject:self
+ withMethod:@selector(mediaPlayerTimeChanged:)
+ withArgumentAsObject:[NSNumber numberWithLongLong:event->u.media_instance_position_changed.new_position]];
+
[[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
withDelegateMethod:@selector(mediaPlayerTimeChanged:)
withNotificationName:VLCMediaPlayerTimeChanged];
-
+ [pool release];
}
static void HandleMediaInstanceStateChanged(const libvlc_event_t *event, void *self)
@interface VLCMediaPlayer (Private)
- (void)registerObservers;
- (void)unregisterObservers;
+- (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
@end
@implementation VLCMediaPlayer
- (id)init
{
- self = [self initWithVideoView:nil];
- return self;
+ return [self initWithVideoView:nil];
}
- (id)initWithVideoView:(VLCVideoView *)aVideoView
{
delegate = nil;
media = nil;
-
+ cachedTime = [[VLCTime nullTime] retain];
// Create a media instance, it doesn't matter what library we start off with
// it will change depending on the media descriptor provided to the media
// instance
libvlc_media_instance_release((libvlc_media_instance_t *)instance);
// Get rid of everything else
- instance = nil;
- videoView = nil;
[media release];
-
+ [cachedTime release];
+
[super dealloc];
}
- (VLCTime *)time
{
- libvlc_exception_t ex;
- libvlc_exception_init( &ex );
-
- // Results are returned in seconds...duration is returned in milliseconds
- long long time = libvlc_media_instance_get_time( (libvlc_media_instance_t *)instance, &ex ) * 1000;
- if (libvlc_exception_raised( &ex ))
- {
- libvlc_exception_clear( &ex );
- return [VLCTime nullTime]; // Error in obtaining the time, return a null time defintition (--:--:--)
- }
- else
- return [VLCTime timeWithNumber:[NSNumber numberWithLongLong:time]];
+ return cachedTime;
}
- (void)setChapter:(int)value;
libvlc_event_attach( p_em, libvlc_MediaInstancePlayed, HandleMediaInstanceStateChanged, self, &ex );
libvlc_event_attach( p_em, libvlc_MediaInstancePaused, HandleMediaInstanceStateChanged, self, &ex );
libvlc_event_attach( p_em, libvlc_MediaInstanceReachedEnd, HandleMediaInstanceStateChanged, self, &ex );
+ /* FIXME: We may want to turn that off when none is interested by that */
libvlc_event_attach( p_em, libvlc_MediaInstancePositionChanged, HandleMediaTimeChanged, self, &ex );
quit_on_exception( &ex );
}
libvlc_event_detach( p_em, libvlc_MediaInstanceReachedEnd, HandleMediaInstanceStateChanged, self, NULL );
libvlc_event_detach( p_em, libvlc_MediaInstancePositionChanged, HandleMediaTimeChanged, self, NULL );
}
+- (void)mediaPlayerTimeChanged:(NSNumber *)newTime
+{
+ [self willChangeValueForKey:@"time"];
+ [cachedTime release];
+ cachedTime = [[VLCTime timeWithNumber:newTime] retain];
+ [self didChangeValueForKey:@"time"];
+}
@end