diff --git a/EasyPlayer/AppDelegate.m b/EasyPlayer/AppDelegate.m index 7aee15d..03488f8 100644 --- a/EasyPlayer/AppDelegate.m +++ b/EasyPlayer/AppDelegate.m @@ -46,9 +46,9 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification { - (NSMenu *)applicationDockMenu:(NSApplication *)sender { NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; - NSMenuItem *pre = [[NSMenuItem alloc] initWithTitle:@"上一首" action:@selector(playPreSong) keyEquivalent:@""]; - NSMenuItem *play = [[NSMenuItem alloc] initWithTitle:self.playerController.isPlaying ? @"暂停" : @"播放" action:@selector(resumePlaySong) keyEquivalent:@""]; - NSMenuItem *next = [[NSMenuItem alloc] initWithTitle:@"下一首" action:@selector(playNextSong) keyEquivalent:@""]; + NSMenuItem *pre = [[NSMenuItem alloc] initWithTitle:@"Previous" action:@selector(playPreSong) keyEquivalent:@""]; + NSMenuItem *play = [[NSMenuItem alloc] initWithTitle:self.playerController.isPlaying ? @"Pause" : @"Play" action:@selector(resumePlaySong) keyEquivalent:@""]; + NSMenuItem *next = [[NSMenuItem alloc] initWithTitle:@"Next" action:@selector(playNextSong) keyEquivalent:@""]; [menu addItem:pre]; [menu addItem:play]; [menu addItem:next]; diff --git a/EasyPlayer/Extentions/MusicTools/JWMediaHelper.h b/EasyPlayer/Extentions/MusicTools/JWMediaHelper.h index ea690b8..34ae8ba 100644 --- a/EasyPlayer/Extentions/MusicTools/JWMediaHelper.h +++ b/EasyPlayer/Extentions/MusicTools/JWMediaHelper.h @@ -30,6 +30,7 @@ + (NSImage*)innerCoverImageForURL:(NSURL*)url; + (NSDictionary *)id3InfoForURL:(NSURL*)url; ++ (void)scanSupportedMediaForFileURL:(NSURL*)fileURL into:(NSMutableArray*)array; + (void)getLrcForTrack:(JWTrack*)track onComplete:(void (^)(NSString*, JWTrack *track, NSError *))block; + (void)getAlbumImageForTrack:(JWTrack*)track onComplete:(void (^)(NSImage*, JWTrack *track, NSError *))block; diff --git a/EasyPlayer/Extentions/MusicTools/JWMediaHelper.m b/EasyPlayer/Extentions/MusicTools/JWMediaHelper.m index df6a46f..d44db67 100644 --- a/EasyPlayer/Extentions/MusicTools/JWMediaHelper.m +++ b/EasyPlayer/Extentions/MusicTools/JWMediaHelper.m @@ -30,6 +30,25 @@ @implementation JWMediaHelper ++ (void)scanSupportedMediaForFileURL:(NSURL*)fileURL into:(NSMutableArray*)array { + NSDictionary *id3Dic = [self id3InfoForURL:fileURL]; + if(id3Dic) { + JWTrack *track = [[JWTrack alloc] initFromID3Info:id3Dic url:fileURL]; + track.sourceType = TrackSourceTypeLocal; + + if (id3Dic[@"picture"]) { + NSImage *coverImg = [[NSImage alloc] initWithData:id3Dic[@"picture"]]; + NSString *albumPath = [JWFileManager getCoverPath]; + if (albumPath) { + NSString *destination = [albumPath stringByAppendingPathComponent:[track cacheKey]]; + [coverImg saveAsJPGFileForPath:destination]; + } + + } + [array addObject:track]; + } +} + + (NSImage*)innerCoverImageForURL:(NSURL*)fileURL { AudioFileID audioFile; OSStatus theErr = noErr; diff --git a/EasyPlayer/PlayerViewController.m b/EasyPlayer/PlayerViewController.m index f02f059..952b2d4 100644 --- a/EasyPlayer/PlayerViewController.m +++ b/EasyPlayer/PlayerViewController.m @@ -291,7 +291,7 @@ - (IBAction)addButtonClicked:(NSButton *)sender { sender.state = 1; NSOpenPanel* openDlg = [NSOpenPanel openPanel]; [openDlg setCanChooseFiles:YES]; - [openDlg setCanChooseDirectories:YES]; + [openDlg setCanChooseDirectories:NO]; [openDlg setAllowsMultipleSelection:YES]; NSArray *urlArray; @@ -303,23 +303,7 @@ - (IBAction)addButtonClicked:(NSButton *)sender { NSMutableArray *newTracks = [NSMutableArray array]; for (NSURL *url in urlArray) { - NSDictionary *id3Dic = [JWMediaHelper id3InfoForURL:url]; - if(id3Dic) { - JWTrack *track = [[JWTrack alloc] initFromID3Info:id3Dic url:url]; - track.sourceType = TrackSourceTypeLocal; - - if (id3Dic[@"picture"]) { - NSImage *coverImg = [[NSImage alloc] initWithData:id3Dic[@"picture"]]; - NSString *albumPath = [JWFileManager getCoverPath]; - if (albumPath) { - NSString *destination = [albumPath stringByAppendingPathComponent:[track cacheKey]]; - [coverImg saveAsJPGFileForPath:destination]; - } - - } - - [newTracks addObject:track]; - } + [JWMediaHelper scanSupportedMediaForFileURL:url into:newTracks]; } NSMutableArray *mutable = [NSMutableArray arrayWithArray:self.items];