Commit af252afb authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCMediaPlayer.m: Enable bindings uses on the @"time" key.

parent cf0875cc
...@@ -43,10 +43,15 @@ static void HandleMediaInstanceVolumeChanged(const libvlc_event_t *event, void * ...@@ -43,10 +43,15 @@ static void HandleMediaInstanceVolumeChanged(const libvlc_event_t *event, void *
static void HandleMediaTimeChanged(const libvlc_event_t * event, void * self) 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 [[VLCEventManager sharedManager] callOnMainThreadDelegateOfObject:self
withDelegateMethod:@selector(mediaPlayerTimeChanged:) withDelegateMethod:@selector(mediaPlayerTimeChanged:)
withNotificationName:VLCMediaPlayerTimeChanged]; withNotificationName:VLCMediaPlayerTimeChanged];
[pool release];
} }
static void HandleMediaInstanceStateChanged(const libvlc_event_t *event, void *self) static void HandleMediaInstanceStateChanged(const libvlc_event_t *event, void *self)
...@@ -74,13 +79,13 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state) ...@@ -74,13 +79,13 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state)
@interface VLCMediaPlayer (Private) @interface VLCMediaPlayer (Private)
- (void)registerObservers; - (void)registerObservers;
- (void)unregisterObservers; - (void)unregisterObservers;
- (void)mediaPlayerTimeChanged:(NSNumber *)newTime;
@end @end
@implementation VLCMediaPlayer @implementation VLCMediaPlayer
- (id)init - (id)init
{ {
self = [self initWithVideoView:nil]; return [self initWithVideoView:nil];
return self;
} }
- (id)initWithVideoView:(VLCVideoView *)aVideoView - (id)initWithVideoView:(VLCVideoView *)aVideoView
...@@ -89,7 +94,7 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state) ...@@ -89,7 +94,7 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state)
{ {
delegate = nil; delegate = nil;
media = nil; media = nil;
cachedTime = [[VLCTime nullTime] retain];
// Create a media instance, it doesn't matter what library we start off with // 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 // it will change depending on the media descriptor provided to the media
// instance // instance
...@@ -116,9 +121,8 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state) ...@@ -116,9 +121,8 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state)
libvlc_media_instance_release((libvlc_media_instance_t *)instance); libvlc_media_instance_release((libvlc_media_instance_t *)instance);
// Get rid of everything else // Get rid of everything else
instance = nil;
videoView = nil;
[media release]; [media release];
[cachedTime release];
[super dealloc]; [super dealloc];
} }
...@@ -282,18 +286,7 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state) ...@@ -282,18 +286,7 @@ NSString *VLCMediaPlayerStateToString(VLCMediaPlayerState state)
- (VLCTime *)time - (VLCTime *)time
{ {
libvlc_exception_t ex; return cachedTime;
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]];
} }
- (void)setChapter:(int)value; - (void)setChapter:(int)value;
...@@ -518,6 +511,7 @@ static const VLCMediaPlayerState libvlc_to_local_state[] = ...@@ -518,6 +511,7 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
libvlc_event_attach( p_em, libvlc_MediaInstancePlayed, HandleMediaInstanceStateChanged, self, &ex ); 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_MediaInstancePaused, HandleMediaInstanceStateChanged, self, &ex );
libvlc_event_attach( p_em, libvlc_MediaInstanceReachedEnd, 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 ); libvlc_event_attach( p_em, libvlc_MediaInstancePositionChanged, HandleMediaTimeChanged, self, &ex );
quit_on_exception( &ex ); quit_on_exception( &ex );
} }
...@@ -530,4 +524,11 @@ static const VLCMediaPlayerState libvlc_to_local_state[] = ...@@ -530,4 +524,11 @@ static const VLCMediaPlayerState libvlc_to_local_state[] =
libvlc_event_detach( p_em, libvlc_MediaInstanceReachedEnd, HandleMediaInstanceStateChanged, self, NULL ); libvlc_event_detach( p_em, libvlc_MediaInstanceReachedEnd, HandleMediaInstanceStateChanged, self, NULL );
libvlc_event_detach( p_em, libvlc_MediaInstancePositionChanged, HandleMediaTimeChanged, 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 @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment