Commit 1fb4f986 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

MacOSX/Framework/VLCMedia: Documentation, code cleanup and and use Objective-C...

MacOSX/Framework/VLCMedia: Documentation, code cleanup and and use Objective-C 2.0 @property. (Patch by Enrique Osuna).
parent a14a5bea
...@@ -30,32 +30,30 @@ ...@@ -30,32 +30,30 @@
/** /**
* Standard dictionary keys for retreiving meta data. * Standard dictionary keys for retreiving meta data.
*/ */
extern NSString *VLCMetaInformationTitle; /* NSString */ extern NSString * VLCMetaInformationTitle; /* NSString */
extern NSString *VLCMetaInformationArtist; /* NSString */ extern NSString * VLCMetaInformationArtist; /* NSString */
extern NSString *VLCMetaInformationTitle; /* NSString */ extern NSString * VLCMetaInformationGenre; /* NSString */
extern NSString *VLCMetaInformationArtist; /* NSString */ extern NSString * VLCMetaInformationCopyright; /* NSString */
extern NSString *VLCMetaInformationGenre; /* NSString */ extern NSString * VLCMetaInformationAlbum; /* NSString */
extern NSString *VLCMetaInformationCopyright; /* NSString */ extern NSString * VLCMetaInformationTrackNumber; /* NSString */
extern NSString *VLCMetaInformationAlbum; /* NSString */ extern NSString * VLCMetaInformationDescription; /* NSString */
extern NSString *VLCMetaInformationTrackNumber; /* NSString */ extern NSString * VLCMetaInformationRating; /* NSString */
extern NSString *VLCMetaInformationDescription; /* NSString */ extern NSString * VLCMetaInformationDate; /* NSString */
extern NSString *VLCMetaInformationRating; /* NSString */ extern NSString * VLCMetaInformationSetting; /* NSString */
extern NSString *VLCMetaInformationDate; /* NSString */ extern NSString * VLCMetaInformationURL; /* NSString */
extern NSString *VLCMetaInformationSetting; /* NSString */ extern NSString * VLCMetaInformationLanguage; /* NSString */
extern NSString *VLCMetaInformationURL; /* NSString */ extern NSString * VLCMetaInformationNowPlaying; /* NSString */
extern NSString *VLCMetaInformationLanguage; /* NSString */ extern NSString * VLCMetaInformationPublisher; /* NSString */
extern NSString *VLCMetaInformationNowPlaying; /* NSString */ extern NSString * VLCMetaInformationEncodedBy; /* NSString */
extern NSString *VLCMetaInformationPublisher; /* NSString */ extern NSString * VLCMetaInformationArtworkURL; /* NSString */
extern NSString *VLCMetaInformationEncodedBy; /* NSString */ extern NSString * VLCMetaInformationArtwork; /* NSImage */
extern NSString *VLCMetaInformationArtworkURL; /* NSString */ extern NSString * VLCMetaInformationTrackID; /* NSString */
extern NSString *VLCMetaInformationArtwork; /* NSImage */
extern NSString *VLCMetaInformationTrackID; /* NSString */
/* Notification Messages */ /* Notification Messages */
/** /**
* Available notification messages. * Available notification messages.
*/ */
extern NSString *VLCMediaMetaChanged; //< Notification message for when the media's meta data has changed extern NSString * VLCMediaMetaChanged; //< Notification message for when the media's meta data has changed
// Forward declarations, supresses compiler error messages // Forward declarations, supresses compiler error messages
@class VLCMediaList; @class VLCMediaList;
...@@ -121,28 +119,52 @@ typedef enum VLCMediaState ...@@ -121,28 +119,52 @@ typedef enum VLCMediaState
/* Object Factories */ /* Object Factories */
/** /**
* Manufactures a new VLCMedia object using the URL specified. Will return nil if * Manufactures a new VLCMedia object using the URL specified.
* the specified URL references a directory that does not comply with DVD file
* structure.
* \param anURL URL to media to be accessed. * \param anURL URL to media to be accessed.
* \return A new VLCMedia object, only if there were no errors. This object * \return A new VLCMedia object, only if there were no errors. This object
* will be automatically released. * will be automatically released.
* \see initWithMediaURL * \see initWithMediaURL
*/ */
+ (id)mediaWithURL:(NSURL *)anURL; + (id)mediaWithURL:(NSURL *)anURL;
/**
* Manufactures a new VLCMedia object using the path specified.
* \param aPath Path to the media to be accessed.
* \return A new VLCMedia object, only if there were no errors. This object
* will be automatically released.
* \see initWithPath
*/
+ (id)mediaWithPath:(NSString *)aPath; + (id)mediaWithPath:(NSString *)aPath;
+ (id)mediaAsNodeWithName:(NSString *)aName;
/**
* TODO
* \param aName TODO
* \return a new VLCMedia object, only if there were no errors. This object
* will be automatically released.
* \see initAsNodeWithName
*/
+ (id)mediaAsNodeWithName:(NSString *)aName;
/* Initializers */ /* Initializers */
/** /**
* Initializes a new VLCMedia object to use the specified URL. Will return nil if * Initializes a new VLCMedia object to use the specified URL.
* the specified URL references a directory that does not comply with DVD file * \param aPath Path to media to be accessed.
* structure. * \return A new VLCMedia object, only if there were no errors.
* \param aPath URL to media to be accessed. */
- (id)initWithURL:(NSURL *)anURL;
/**
* Initializes a new VLCMedia object to use the specified path.
* \param aPath Path to media to be accessed.
* \return A new VLCMedia object, only if there were no errors. * \return A new VLCMedia object, only if there were no errors.
*/ */
- (id)initWithPath:(NSString *)aPath; - (id)initWithPath:(NSString *)aPath;
/**
* TODO
* \param aName TODO
* \return A new VLCMedia object, only if there were no errors.
*/
- (id)initAsNodeWithName:(NSString *)aName; - (id)initAsNodeWithName:(NSString *)aName;
/** /**
...@@ -158,22 +180,16 @@ typedef enum VLCMediaState ...@@ -158,22 +180,16 @@ typedef enum VLCMediaState
/* Properties */ /* Properties */
/** /**
* Sets the receiver's delegate. * Receiver's delegate.
* \param delegate The delegate for the receiver.
*/ */
- (void)setDelegate:(id)delegate; @property (assign) id delegate;
/** /**
* Returns the receiver's delegate * A VLCTime object describing the length of the media resource, only if it is
* \return The receiver's delegate * available. Use lengthWaitUntilDate: to wait for a specified length of time.
* \see lengthWaitUntilDate
*/ */
- (id)delegate; @property (readonly) VLCTime * length;
/**
* Returns a VLCTime object describing the length of the media resource.
* \return The length of the media resource.
*/
- (VLCTime *)length;
/** /**
* Returns a VLCTime object describing the length of the media resource, * Returns a VLCTime object describing the length of the media resource,
...@@ -185,29 +201,28 @@ typedef enum VLCMediaState ...@@ -185,29 +201,28 @@ typedef enum VLCMediaState
*/ */
- (VLCTime *)lengthWaitUntilDate:(NSDate *)aDate; - (VLCTime *)lengthWaitUntilDate:(NSDate *)aDate;
- (BOOL)isPreparsed; /**
* Determines if the media has already been preparsed.
*/
@property (readonly) BOOL isPreparsed;
/** /**
* Returns the URL for the receiver's media resource. * The URL for the receiver's media resource.
* \return The URL for the receiver's media resource.
*/ */
- (NSString *)url; @property (readonly) NSString * url;
/** /**
* Returns the receiver's sub list. * The receiver's sub list.
* \return The receiver's sub list.
*/ */
- (VLCMediaList *)subitems; @property (readonly) VLCMediaList * subitems;
/** /**
* Returns the receiver's meta data as a NSDictionary object. * The receiver's meta data as a NSDictionary object.
* \return The receiver's meta data as a NSDictionary object.
*/ */
- (NSDictionary *)metaDictionary; @property (readonly) NSDictionary * metaDictionary;
/** /**
* Returns the receiver's state. * The receiver's state, such as Playing, Error, NothingSpecial, Buffering.
* \return The receiver's state, such as Playing, Error, NothingSpecial, Buffering.
*/ */
- (VLCMediaState)state; @property (readonly) VLCMediaState state;
@end @end
...@@ -30,27 +30,27 @@ ...@@ -30,27 +30,27 @@
#include <vlc/libvlc.h> #include <vlc/libvlc.h>
/* Meta Dictionary Keys */ /* Meta Dictionary Keys */
NSString *VLCMetaInformationTitle = @"title"; NSString * VLCMetaInformationTitle = @"title";
NSString *VLCMetaInformationArtist = @"artist"; NSString * VLCMetaInformationArtist = @"artist";
NSString *VLCMetaInformationGenre = @"genre"; NSString * VLCMetaInformationGenre = @"genre";
NSString *VLCMetaInformationCopyright = @"copyright"; NSString * VLCMetaInformationCopyright = @"copyright";
NSString *VLCMetaInformationAlbum = @"album"; NSString * VLCMetaInformationAlbum = @"album";
NSString *VLCMetaInformationTrackNumber = @"trackNumber"; NSString * VLCMetaInformationTrackNumber = @"trackNumber";
NSString *VLCMetaInformationDescription = @"description"; NSString * VLCMetaInformationDescription = @"description";
NSString *VLCMetaInformationRating = @"rating"; NSString * VLCMetaInformationRating = @"rating";
NSString *VLCMetaInformationDate = @"date"; NSString * VLCMetaInformationDate = @"date";
NSString *VLCMetaInformationSetting = @"setting"; NSString * VLCMetaInformationSetting = @"setting";
NSString *VLCMetaInformationURL = @"url"; NSString * VLCMetaInformationURL = @"url";
NSString *VLCMetaInformationLanguage = @"language"; NSString * VLCMetaInformationLanguage = @"language";
NSString *VLCMetaInformationNowPlaying = @"nowPlaying"; NSString * VLCMetaInformationNowPlaying = @"nowPlaying";
NSString *VLCMetaInformationPublisher = @"publisher"; NSString * VLCMetaInformationPublisher = @"publisher";
NSString *VLCMetaInformationEncodedBy = @"encodedBy"; NSString * VLCMetaInformationEncodedBy = @"encodedBy";
NSString *VLCMetaInformationArtworkURL = @"artworkURL"; NSString * VLCMetaInformationArtworkURL = @"artworkURL";
NSString *VLCMetaInformationArtwork = @"artwork"; NSString * VLCMetaInformationArtwork = @"artwork";
NSString *VLCMetaInformationTrackID = @"trackID"; NSString * VLCMetaInformationTrackID = @"trackID";
/* Notification Messages */ /* Notification Messages */
NSString *VLCMediaMetaChanged = @"VLCMediaMetaChanged"; NSString * VLCMediaMetaChanged = @"VLCMediaMetaChanged";
/****************************************************************************** /******************************************************************************
* Interface (Private) * Interface (Private)
...@@ -93,7 +93,7 @@ static inline VLCMediaState LibVLCStateToMediaState( libvlc_state_t state ) ...@@ -93,7 +93,7 @@ static inline VLCMediaState LibVLCStateToMediaState( libvlc_state_t state )
/****************************************************************************** /******************************************************************************
* LibVLC Event Callback * LibVLC Event Callback
*/ */
static void HandleMediaMetaChanged(const libvlc_event_t *event, void *self) static void HandleMediaMetaChanged(const libvlc_event_t * event, void * self)
{ {
if( event->u.media_descriptor_meta_changed.meta_type == libvlc_meta_Publisher || if( event->u.media_descriptor_meta_changed.meta_type == libvlc_meta_Publisher ||
event->u.media_descriptor_meta_changed.meta_type == libvlc_meta_NowPlaying ) event->u.media_descriptor_meta_changed.meta_type == libvlc_meta_NowPlaying )
...@@ -102,27 +102,27 @@ static void HandleMediaMetaChanged(const libvlc_event_t *event, void *self) ...@@ -102,27 +102,27 @@ static void HandleMediaMetaChanged(const libvlc_event_t *event, void *self)
* And they occure a lot */ * And they occure a lot */
return; return;
} }
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[VLCEventManager sharedManager] callOnMainThreadObject:self [[VLCEventManager sharedManager] callOnMainThreadObject:self
withMethod:@selector(metaChanged:) withMethod:@selector(metaChanged:)
withArgumentAsObject:[VLCMedia metaTypeToString:event->u.media_descriptor_meta_changed.meta_type]]; withArgumentAsObject:[VLCMedia metaTypeToString:event->u.media_descriptor_meta_changed.meta_type]];
[pool release]; [pool release];
} }
static void HandleMediaDurationChanged(const libvlc_event_t *event, void *self) //static void HandleMediaDurationChanged(const libvlc_event_t * event, void * self)
{ //{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//
//[[VLCEventManager sharedManager] callOnMainThreadObject:self // [[VLCEventManager sharedManager] callOnMainThreadObject:self
// withMethod:@selector(setLength:) // withMethod:@selector(setLength:)
// withArgumentAsObject:[VLCTime timeWithNumber: // withArgumentAsObject:[VLCTime timeWithNumber:
// [NSNumber numberWithLongLong:event->u.media_descriptor_duration_changed.new_duration]]]; // [NSNumber numberWithLongLong:event->u.media_descriptor_duration_changed.new_duration]]];
[pool release]; // [pool release];
} //}
static void HandleMediaStateChanged(const libvlc_event_t *event, void *self) static void HandleMediaStateChanged(const libvlc_event_t * event, void * self)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[VLCEventManager sharedManager] callOnMainThreadObject:self [[VLCEventManager sharedManager] callOnMainThreadObject:self
withMethod:@selector(setState:) withMethod:@selector(setState:)
withArgumentAsObject:[NSNumber numberWithInt: withArgumentAsObject:[NSNumber numberWithInt:
...@@ -130,9 +130,9 @@ static void HandleMediaStateChanged(const libvlc_event_t *event, void *self) ...@@ -130,9 +130,9 @@ static void HandleMediaStateChanged(const libvlc_event_t *event, void *self)
[pool release]; [pool release];
} }
static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[VLCEventManager sharedManager] callOnMainThreadObject:self [[VLCEventManager sharedManager] callOnMainThreadObject:self
withMethod:@selector(subItemAdded) withMethod:@selector(subItemAdded)
withArgumentAsObject:nil]; withArgumentAsObject:nil];
...@@ -143,14 +143,14 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -143,14 +143,14 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
* Implementation * Implementation
*/ */
@implementation VLCMedia @implementation VLCMedia
+ (id)mediaWithPath:(NSString *)aPath; + (id)mediaWithURL:(NSURL *)anURL;
{ {
return [[[VLCMedia alloc] initWithPath:aPath] autorelease]; return [[[VLCMedia alloc] initWithURL:anURL] autorelease];
} }
+ (id)mediaWithURL:(NSURL *)aURL; + (id)mediaWithPath:(NSString *)aPath;
{ {
return [[[VLCMedia alloc] initWithPath:[aURL path]] autorelease]; return [[[VLCMedia alloc] initWithPath:aPath] autorelease];
} }
+ (id)mediaAsNodeWithName:(NSString *)aName; + (id)mediaAsNodeWithName:(NSString *)aName;
...@@ -158,20 +158,24 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -158,20 +158,24 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
return [[[VLCMedia alloc] initAsNodeWithName:aName] autorelease]; return [[[VLCMedia alloc] initAsNodeWithName:aName] autorelease];
} }
- (id)initAsNodeWithName:(NSString *)aName - (id)initWithURL:(NSURL *)anURL
{
return [self initWithPath:[anURL path]];
}
- (id)initWithPath:(NSString *)aPath
{ {
if (self = [super init]) if (self = [super init])
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
p_md = libvlc_media_descriptor_new_as_node( p_md = libvlc_media_descriptor_new([VLCLibrary sharedInstance],
[VLCLibrary sharedInstance], [aPath UTF8String],
[aName UTF8String],
&ex); &ex);
quit_on_exception(&ex); quit_on_exception(&ex);
url = [aName copy]; url = [aPath copy];
delegate = nil; delegate = nil;
metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3]; metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
...@@ -184,20 +188,19 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -184,20 +188,19 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
return self; return self;
} }
- (id)initWithPath:(NSString *)aPath - (id)initAsNodeWithName:(NSString *)aName
{ {
if (self = [super init]) if (self = [super init])
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
p_md = libvlc_media_descriptor_new([VLCLibrary sharedInstance], p_md = libvlc_media_descriptor_new_as_node([VLCLibrary sharedInstance],
[aPath UTF8String], [aName UTF8String],
&ex); &ex);
quit_on_exception(&ex); quit_on_exception(&ex);
url = [aPath copy]; url = [aName copy];
delegate = nil; delegate = nil;
metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3]; metaDictionary = [[NSMutableDictionary alloc] initWithCapacity:3];
...@@ -219,9 +222,9 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -219,9 +222,9 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
/* We must make sure we won't receive new event after an upcoming dealloc /* We must make sure we won't receive new event after an upcoming dealloc
* We also may receive a -retain in some event callback that may occcur * We also may receive a -retain in some event callback that may occcur
* Before libvlc_event_detach. So this can't happen in dealloc */ * Before libvlc_event_detach. So this can't happen in dealloc */
libvlc_event_manager_t *p_em = libvlc_media_descriptor_event_manager(p_md, NULL); libvlc_event_manager_t * p_em = libvlc_media_descriptor_event_manager(p_md, NULL);
libvlc_event_detach(p_em, libvlc_MediaDescriptorMetaChanged, HandleMediaMetaChanged, self, NULL); libvlc_event_detach(p_em, libvlc_MediaDescriptorMetaChanged, HandleMediaMetaChanged, self, NULL);
libvlc_event_detach(p_em, libvlc_MediaDescriptorDurationChanged, HandleMediaDurationChanged, self, NULL); // libvlc_event_detach(p_em, libvlc_MediaDescriptorDurationChanged, HandleMediaDurationChanged, self, NULL);
libvlc_event_detach(p_em, libvlc_MediaDescriptorStateChanged, HandleMediaStateChanged, self, NULL); libvlc_event_detach(p_em, libvlc_MediaDescriptorStateChanged, HandleMediaStateChanged, self, NULL);
libvlc_event_detach(p_em, libvlc_MediaDescriptorSubItemAdded, HandleMediaSubItemAdded, self, NULL); libvlc_event_detach(p_em, libvlc_MediaDescriptorSubItemAdded, HandleMediaSubItemAdded, self, NULL);
} }
...@@ -233,7 +236,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -233,7 +236,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
{ {
// Testing to see if the pointer exists is not required, if the pointer is null // Testing to see if the pointer exists is not required, if the pointer is null
// then the release message is not sent to it. // then the release message is not sent to it.
[self setDelegate:nil]; delegate = nil;
[self setLength:nil]; [self setLength:nil];
[url release]; [url release];
...@@ -247,7 +250,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -247,7 +250,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
- (NSString *)description - (NSString *)description
{ {
NSString *result = [metaDictionary objectForKey:VLCMetaInformationTitle]; NSString * result = [metaDictionary objectForKey:VLCMetaInformationTitle];
return [NSString stringWithFormat:@"<%@ %p> %@", [self className], self, (result ? result : url)]; return [NSString stringWithFormat:@"<%@ %p> %@", [self className], self, (result ? result : url)];
} }
...@@ -261,15 +264,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -261,15 +264,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
return [[self url] compare:[media url]]; return [[self url] compare:[media url]];
} }
- (NSString *)url @synthesize delegate;
{
return [[url copy] autorelease];
}
- (VLCMediaList *)subitems
{
return subitems;
}
- (VLCTime *)length - (VLCTime *)length
{ {
...@@ -290,9 +285,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -290,9 +285,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
{ {
static const long long thread_sleep = 10000; static const long long thread_sleep = 10000;
if (![url hasPrefix:@"file://"]) if (!length)
return [self length];
else if (!length)
{ {
while (!length && ![self isPreparsed] && [aDate timeIntervalSinceNow] > 0) while (!length && ![self isPreparsed] && [aDate timeIntervalSinceNow] > 0)
{ {
...@@ -314,25 +307,10 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -314,25 +307,10 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
return libvlc_media_descriptor_is_preparsed( p_md, NULL ); return libvlc_media_descriptor_is_preparsed( p_md, NULL );
} }
- (NSDictionary *)metaDictionary @synthesize url;
{ @synthesize subitems;
return metaDictionary; @synthesize metaDictionary;
} @synthesize state;
- (void)setDelegate:(id)value
{
delegate = value;
}
- (id)delegate
{
return delegate;
}
- (VLCMediaState)state
{
return state;
}
@end @end
/****************************************************************************** /******************************************************************************
...@@ -357,6 +335,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -357,6 +335,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
quit_on_exception( &ex ); quit_on_exception( &ex );
url = [[NSString stringWithUTF8String:p_url] retain]; url = [[NSString stringWithUTF8String:p_url] retain];
free( p_url );
libvlc_media_descriptor_retain( md ); libvlc_media_descriptor_retain( md );
p_md = md; p_md = md;
...@@ -441,14 +420,14 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -441,14 +420,14 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
libvlc_media_descriptor_set_user_data( p_md, (void*)self, &ex ); libvlc_media_descriptor_set_user_data( p_md, (void*)self, &ex );
quit_on_exception( &ex ); quit_on_exception( &ex );
libvlc_event_manager_t *p_em = libvlc_media_descriptor_event_manager( p_md, &ex ); libvlc_event_manager_t * p_em = libvlc_media_descriptor_event_manager( p_md, &ex );
libvlc_event_attach(p_em, libvlc_MediaDescriptorMetaChanged, HandleMediaMetaChanged, self, &ex); libvlc_event_attach(p_em, libvlc_MediaDescriptorMetaChanged, HandleMediaMetaChanged, self, &ex);
libvlc_event_attach(p_em, libvlc_MediaDescriptorDurationChanged, HandleMediaDurationChanged, self, &ex); // libvlc_event_attach(p_em, libvlc_MediaDescriptorDurationChanged, HandleMediaDurationChanged, self, &ex);
libvlc_event_attach(p_em, libvlc_MediaDescriptorStateChanged, HandleMediaStateChanged, self, &ex); libvlc_event_attach(p_em, libvlc_MediaDescriptorStateChanged, HandleMediaStateChanged, self, &ex);
libvlc_event_attach(p_em, libvlc_MediaDescriptorSubItemAdded, HandleMediaSubItemAdded, self, &ex); libvlc_event_attach(p_em, libvlc_MediaDescriptorSubItemAdded, HandleMediaSubItemAdded, self, &ex);
quit_on_exception( &ex ); quit_on_exception( &ex );
libvlc_media_list_t *p_mlist = libvlc_media_descriptor_subitems( p_md, NULL ); libvlc_media_list_t * p_mlist = libvlc_media_descriptor_subitems( p_md, NULL );
if (!p_mlist) if (!p_mlist)
subitems = nil; subitems = nil;
...@@ -467,8 +446,8 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -467,8 +446,8 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
- (void)fetchMetaInformationFromLibVLCWithType:(NSString *)metaType - (void)fetchMetaInformationFromLibVLCWithType:(NSString *)metaType
{ {
char * psz_value = libvlc_media_descriptor_get_meta( p_md, [VLCMedia stringToMetaType:metaType], NULL); char * psz_value = libvlc_media_descriptor_get_meta( p_md, [VLCMedia stringToMetaType:metaType], NULL);
NSString *newValue = psz_value ? [NSString stringWithUTF8String: psz_value] : nil; NSString * newValue = psz_value ? [NSString stringWithUTF8String: psz_value] : nil;
NSString *oldValue = [metaDictionary valueForKey:metaType]; NSString * oldValue = [metaDictionary valueForKey:metaType];
free(psz_value); free(psz_value);
if ( !(newValue && oldValue && [oldValue compare:newValue] == NSOrderedSame) ) if ( !(newValue && oldValue && [oldValue compare:newValue] == NSOrderedSame) )
...@@ -485,10 +464,9 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -485,10 +464,9 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
} }
} }
- (void)fetchMetaInformationForArtWorkWithURL:(NSString *)anURL - (void)fetchMetaInformationForArtWorkWithURL:(NSString *)anURL
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Go ahead and load up the art work // Go ahead and load up the art work
NSURL * artUrl = [NSURL URLWithString:[anURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURL * artUrl = [NSURL URLWithString:[anURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
...@@ -497,7 +475,8 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -497,7 +475,8 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
// If anything was found, lets save it to the meta data dictionary // If anything was found, lets save it to the meta data dictionary
if (art) if (art)
{ {
@synchronized(metaDictionary) { @synchronized(metaDictionary)
{
[metaDictionary setObject:art forKey:VLCMetaInformationArtwork]; [metaDictionary setObject:art forKey:VLCMetaInformationArtwork];
} }
} }
...@@ -515,7 +494,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self) ...@@ -515,7 +494,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t *event, void *self)
if( subitems ) if( subitems )
return; /* Nothing to do */ return; /* Nothing to do */
libvlc_media_list_t *p_mlist = libvlc_media_descriptor_subitems( p_md, NULL ); libvlc_media_list_t * p_mlist = libvlc_media_descriptor_subitems( p_md, NULL );
NSAssert( p_mlist, @"The mlist shouldn't be nil, we are receiving a subItemAdded"); NSAssert( p_mlist, @"The mlist shouldn't be nil, we are receiving a subItemAdded");
......
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