]> git.sesse.net Git - vlc/blobdiff - projects/macosx/framework/Sources/VLCMedia.m
macosx/framework: Remove the newly removed exception parameter.
[vlc] / projects / macosx / framework / Sources / VLCMedia.m
index f22fb6f461837dfcad1c8d6de264f6925ee6c91d..22a09b747b686923166963f70fc91228db3f3cb5 100644 (file)
@@ -118,21 +118,21 @@ static void HandleMediaMetaChanged(const libvlc_event_t * event, void * self)
     [pool release];
 }
 
-//static void HandleMediaDurationChanged(const libvlc_event_t * event, void * self)
-//{
-//    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-//    
-//    [[VLCEventManager sharedManager] callOnMainThreadObject:self
-//                                                 withMethod:@selector(setLength:)
-//                                       withArgumentAsObject:[VLCTime timeWithNumber:
-//                                           [NSNumber numberWithLongLong:event->u.media_duration_changed.new_duration]]];
-//    [pool release];
-//}
+static void HandleMediaDurationChanged(const libvlc_event_t * event, void * self)
+{
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+    [[VLCEventManager sharedManager] callOnMainThreadObject:self
+                                                 withMethod:@selector(setLength:)
+                                       withArgumentAsObject:[VLCTime timeWithNumber:
+                                           [NSNumber numberWithLongLong:event->u.media_duration_changed.new_duration]]];
+    [pool release];
+}
 
 static void HandleMediaStateChanged(const libvlc_event_t * event, void * self)
 {
     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-    
+
     [[VLCEventManager sharedManager] callOnMainThreadObject:self
                                                  withMethod:@selector(setStateAsNumber:)
                                        withArgumentAsObject:[NSNumber numberWithInt:
@@ -174,20 +174,20 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 }
 
 - (id)initWithURL:(NSURL *)anURL
-{        
+{
     if (self = [super init])
     {
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
-        
+
         p_md = libvlc_media_new([VLCLibrary sharedInstance],
                                            [[anURL absoluteString] UTF8String],
                                            &ex);
         catch_exception(&ex);
-        
+
         delegate = nil;
         metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
-        
+
         // This value is set whenever the demuxer figures out what the length is.
         // TODO: Easy way to tell the length of the movie without having to instiate the demuxer.  Maybe cached info?
         length = nil;
@@ -198,12 +198,12 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 }
 
 - (id)initAsNodeWithName:(NSString *)aName
-{        
+{
     if (self = [super init])
     {
         libvlc_exception_t ex;
         libvlc_exception_init(&ex);
-        
+
         p_md = libvlc_media_new_as_node([VLCLibrary sharedInstance],
                                                    [aName UTF8String],
                                                    &ex);
@@ -211,11 +211,11 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
         delegate = nil;
         metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
-        
+
         // This value is set whenever the demuxer figures out what the length is.
         // TODO: Easy way to tell the length of the movie without having to instiate the demuxer.  Maybe cached info?
         length = nil;
-        
+
         [self initInternalMediaDescriptor];
     }
     return self;
@@ -231,10 +231,10 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
              * We also may receive a -retain in some event callback that may occcur
              * Before libvlc_event_detach. So this can't happen in dealloc */
             libvlc_event_manager_t * p_em = libvlc_media_event_manager(p_md);
-            libvlc_event_detach(p_em, libvlc_MediaMetaChanged,     HandleMediaMetaChanged,     self, NULL);
-//            libvlc_event_detach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, self, NULL);
-            libvlc_event_detach(p_em, libvlc_MediaStateChanged,    HandleMediaStateChanged,    self, NULL);
-            libvlc_event_detach(p_em, libvlc_MediaSubItemAdded,    HandleMediaSubItemAdded,    self, NULL);
+            libvlc_event_detach(p_em, libvlc_MediaMetaChanged,     HandleMediaMetaChanged,     self);
+            libvlc_event_detach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, self);
+            libvlc_event_detach(p_em, libvlc_MediaStateChanged,    HandleMediaStateChanged,    self);
+            libvlc_event_detach(p_em, libvlc_MediaSubItemAdded,    HandleMediaSubItemAdded,    self);
         }
         [super release];
     }
@@ -275,11 +275,11 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
 - (VLCTime *)length
 {
-    if (!length) 
+    if (!length)
     {
         // Try figuring out what the length is
         long long duration = libvlc_media_get_duration( p_md, NULL );
-        if (duration > -1) 
+        if (duration > -1)
         {
             [self setLength:[VLCTime timeWithNumber:[NSNumber numberWithLongLong:duration]]];
             return [[length retain] autorelease];
@@ -295,11 +295,15 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
     if (!length)
     {
+        // Force preparsing of this item.
+        [self length];
+
+        // wait until we are preparsed
         while (!length && ![self isPreparsed] && [aDate timeIntervalSinceNow] > 0)
         {
             usleep( thread_sleep );
         }
-        
+
         // So we're done waiting, but sometimes we trap the fact that the parsing
         // was done before the length gets assigned, so lets go ahead and assign
         // it ourselves.
@@ -338,14 +342,14 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
     {
         libvlc_media_retain( md );
         p_md = md;
-        
+
         metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
         [self initInternalMediaDescriptor];
     }
     return self;
 }
 
-- (void *)libVLCMediaDescriptor 
+- (void *)libVLCMediaDescriptor
 {
     return p_md;
 }
@@ -354,6 +358,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 {
     libvlc_media_t * p_md;
     p_md = libvlc_media_duplicate( [media libVLCMediaDescriptor] );
+
     for( NSString * key in [options allKeys] )
     {
         libvlc_media_add_option(p_md, [[NSString stringWithFormat:@"%@=#%@", key, [options objectForKey:key]] UTF8String]);
@@ -428,8 +433,6 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
     libvlc_exception_t ex;
     libvlc_exception_init( &ex );
 
-    artFetched = NO;
-
     char * p_url = libvlc_media_get_mrl( p_md );
 
     url = [[NSURL URLWithString:[NSString stringWithUTF8String:p_url]] retain];
@@ -441,10 +444,10 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
     libvlc_event_manager_t * p_em = libvlc_media_event_manager( p_md );
     libvlc_event_attach(p_em, libvlc_MediaMetaChanged,     HandleMediaMetaChanged,     self, &ex);
-//    libvlc_event_attach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, self, &ex);
+    libvlc_event_attach(p_em, libvlc_MediaDurationChanged, HandleMediaDurationChanged, self, &ex);
     libvlc_event_attach(p_em, libvlc_MediaStateChanged,    HandleMediaStateChanged,    self, &ex);
     libvlc_event_attach(p_em, libvlc_MediaSubItemAdded,    HandleMediaSubItemAdded,    self, &ex);
-    
+
     libvlc_media_list_t * p_mlist = libvlc_media_subitems( p_md );
 
     if (!p_mlist)
@@ -456,10 +459,6 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
     }
 
     state = LibVLCStateToMediaState(libvlc_media_get_state( p_md ));
-
-    /* Force VLCMetaInformationTitle, that will trigger preparsing
-     * And all the other meta will be added through the libvlc event system */
-    [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
 }
 
 - (void)fetchMetaInformationFromLibVLCWithType:(NSString *)metaType
@@ -471,12 +470,12 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
     if ( newValue != oldValue && !(oldValue && newValue && [oldValue compare:newValue] == NSOrderedSame) )
     {
-        if ([metaType isEqualToString:VLCMetaInformationArtworkURL])
+        // Only fetch the art if needed. (ie, create the NSImage, if it was requested before)
+        if (isArtFetched && [metaType isEqualToString:VLCMetaInformationArtworkURL])
         {
-            [NSThread detachNewThreadSelector:@selector(fetchMetaInformationForArtWorkWithURL:) 
+            [NSThread detachNewThreadSelector:@selector(fetchMetaInformationForArtWorkWithURL:)
                                          toTarget:self
                                        withObject:newValue];
-            return;
         }
 
         [metaDictionary setValue:newValue forKeyPath:metaType];
@@ -495,7 +494,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
         // Don't attempt to fetch artwork from remote. Core will do that alone
         if ([artUrl isFileURL])
-            art  = [[[NSImage alloc] initWithContentsOfURL:artUrl] autorelease]; 
+            art  = [[[NSImage alloc] initWithContentsOfURL:artUrl] autorelease];
     }
 
     // If anything was found, lets save it to the meta data dictionary
@@ -542,12 +541,28 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 
 - (id)valueForKeyPath:(NSString *)keyPath
 {
-    if( !artFetched && [keyPath isEqualToString:@"metaDictionary.artwork"])
+    if( !isArtFetched && [keyPath isEqualToString:@"metaDictionary.artwork"])
     {
-        artFetched = YES;
+        isArtFetched = YES;
         /* Force the retrieval of the artwork now that someone asked for it */
         [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
     }
+    else if( !areOthersMetaFetched && [keyPath hasPrefix:@"metaDictionary."])
+    {
+        areOthersMetaFetched = YES;
+        /* Force VLCMetaInformationTitle, that will trigger preparsing
+         * And all the other meta will be added through the libvlc event system */
+        [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationTitle];
+
+    }
+    else if( !isArtURLFetched && [keyPath hasPrefix:@"metaDictionary.artworkURL"])
+    {
+        isArtURLFetched = YES;
+        /* Force isArtURLFetched, that will trigger artwork download eventually
+         * And all the other meta will be added through the libvlc event system */
+        [self fetchMetaInformationFromLibVLCWithType: VLCMetaInformationArtworkURL];
+    }
+
     return [super valueForKeyPath:keyPath];
 }
 @end
@@ -562,8 +577,8 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
 {
     if (length && value && [length compare:value] == NSOrderedSame)
         return;
-        
-    [length release];       
+
+    [length release];
     length = value ? [value retain] : nil;
 }