Ver código fonte

MacOSX/Framework/VLCMedia.m: Implement mediaAsNodeWithName:.

Pierre d'Herbemont 17 anos atrás
pai
commit
f7bee5b2de
2 arquivos alterados com 38 adições e 3 exclusões
  1. 3 0
      Headers/Public/VLCMedia.h
  2. 35 3
      Sources/VLCMedia.m

+ 3 - 0
Headers/Public/VLCMedia.h

@@ -122,6 +122,8 @@ extern NSString *VLCMediaMetaChanged;        //< Notification message for when t
  */
 + (id)mediaWithURL:(NSURL *)anURL;
 + (id)mediaWithPath:(NSString *)aPath;
++ (id)mediaAsNodeWithName:(NSString *)aName;
+
 
 /* Initializers */
 /**
@@ -132,6 +134,7 @@ extern NSString *VLCMediaMetaChanged;        //< Notification message for when t
  * \return A new VLCMedia object, only if there were no errors.
  */
 - (id)initWithPath:(NSString *)aPath;
+- (id)initAsNodeWithName:(NSString *)aName;
 
 /**
  * Returns an NSComparisonResult value that indicates the lexical ordering of 

+ 35 - 3
Sources/VLCMedia.m

@@ -102,12 +102,43 @@ static void HandleMediaDurationChanged(const libvlc_event_t *event, void *self)
 @implementation VLCMedia
 + (id)mediaWithPath:(NSString *)aPath;
 {
-    return [[[VLCMedia alloc] initWithPath:(id)aPath] autorelease];
+    return [[[VLCMedia alloc] initWithPath:aPath] autorelease];
 }
 
 + (id)mediaWithURL:(NSURL *)aURL;
 {
-    return [[[VLCMedia alloc] initWithPath:(id)[aURL path]] autorelease];
+    return [[[VLCMedia alloc] initWithPath:[aURL path]] autorelease];
+}
+
++ (id)mediaAsNodeWithName:(NSString *)aName;
+{
+    return [[[VLCMedia alloc] initAsNodeWithName:aName] autorelease];
+}
+
+- (id)initAsNodeWithName:(NSString *)aName
+{        
+    if (self = [super init])
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+        
+        p_md = libvlc_media_descriptor_new_as_node(
+                                [VLCLibrary sharedInstance],
+                                [aName UTF8String],
+                                &ex);
+        quit_on_exception(&ex);
+        
+        url = [aName copy];
+        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;
 }
 
 - (id)initWithPath:(NSString *)aPath
@@ -172,7 +203,7 @@ static void HandleMediaDurationChanged(const libvlc_event_t *event, void *self)
 - (NSString *)description
 {
     NSString *result = [metaDictionary objectForKey:VLCMetaInformationTitle];
-    return (result ? result : url);
+    return [NSString stringWithFormat:@"<%@ %p> %@", [self className], self, (result ? result : url)];
 }
 
 - (NSComparisonResult)compare:(VLCMedia *)media
@@ -366,6 +397,7 @@ static void HandleMediaDurationChanged(const libvlc_event_t *event, void *self)
     quit_on_exception( &ex );
     
     libvlc_media_list_t *p_mlist = libvlc_media_descriptor_subitems( p_md, NULL );
+
     if (!p_mlist)
         subitems = nil;
     else