Commit e5129e87 authored by Felix Paul Kühne's avatar Felix Paul Kühne

playback: fix meta data export for non-MLFile playback, add support for...

playback: fix meta data export for non-MLFile playback, add support for prev/next through the OS remote calls
parent 9562ec1a
...@@ -635,6 +635,12 @@ ...@@ -635,6 +635,12 @@
[self playPause]; [self playPause];
break; break;
case UIEventSubtypeRemoteControlNextTrack:
[_listPlayer next];
case UIEventSubtypeRemoteControlPreviousTrack:
[_listPlayer previous];
default: default:
break; break;
} }
...@@ -1132,7 +1138,7 @@ ...@@ -1132,7 +1138,7 @@
self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", speed]; self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", speed];
/* rate changed, so update the exported info */ /* rate changed, so update the exported info */
[self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil]; [self performSelectorInBackground:@selector(_updateDisplayedMetadata) withObject:nil];
} }
- (float)_playbackSpeed - (float)_playbackSpeed
...@@ -1249,6 +1255,7 @@ ...@@ -1249,6 +1255,7 @@
NSString *title; NSString *title;
NSString *artist; NSString *artist;
NSString *albumName; NSString *albumName;
NSString *trackNumber;
if (item) { if (item) {
if (item.isAlbumTrack) { if (item.isAlbumTrack) {
...@@ -1260,9 +1267,10 @@ ...@@ -1260,9 +1267,10 @@
} else { } else {
NSDictionary * metaDict = _mediaPlayer.media.metaDictionary; NSDictionary * metaDict = _mediaPlayer.media.metaDictionary;
if (metaDict) { if (metaDict) {
title = metaDict[VLCMetaInformationTitle]; title = metaDict[VLCMetaInformationNowPlaying] ? metaDict[VLCMetaInformationNowPlaying] : metaDict[VLCMetaInformationTitle];
artist = metaDict[VLCMetaInformationArtist]; artist = metaDict[VLCMetaInformationArtist];
albumName = metaDict[VLCMetaInformationAlbum]; albumName = metaDict[VLCMetaInformationAlbum];
trackNumber = metaDict[VLCMetaInformationTrackNumber];
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaItemWithTitle:title Artist:artist andAlbumName:albumName]; self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaItemWithTitle:title Artist:artist andAlbumName:albumName];
} }
} }
...@@ -1276,36 +1284,24 @@ ...@@ -1276,36 +1284,24 @@
if (self.trackNameLabel.text.length < 1 || [self.trackNameLabel.text isEqualToString:@" — — "]) if (self.trackNameLabel.text.length < 1 || [self.trackNameLabel.text isEqualToString:@" — — "])
self.trackNameLabel.text = [[_mediaPlayer.media url] lastPathComponent]; self.trackNameLabel.text = [[_mediaPlayer.media url] lastPathComponent];
[self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil];
}
- (void)_updateExportedPlaybackInformation
{
if (!_mediaItem) {
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
return;
}
MLFile * currentFile = _mediaItem;
/* don't leak sensitive information to the OS, if passcode lock is enabled */ /* don't leak sensitive information to the OS, if passcode lock is enabled */
BOOL passcodeLockEnabled = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPasscodeOnKey] boolValue]; BOOL passcodeLockEnabled = [[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingPasscodeOnKey] boolValue];
/* we omit artwork for now since we had to read it from storage as we can't access
* the artwork cache at the moment - FIXME? */
NSMutableDictionary *currentlyPlayingTrackInfo; NSMutableDictionary *currentlyPlayingTrackInfo;
if (passcodeLockEnabled) if (passcodeLockEnabled)
currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(currentFile.duration.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil]; currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:@(_mediaPlayer.media.length.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil];
else else {
currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: currentFile.title, MPMediaItemPropertyTitle, @(currentFile.duration.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil]; currentlyPlayingTrackInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys: title, MPMediaItemPropertyTitle, @(_mediaPlayer.media.length.intValue / 1000.), MPMediaItemPropertyPlaybackDuration, @(_mediaPlayer.time.intValue / 1000.), MPNowPlayingInfoPropertyElapsedPlaybackTime, @(_mediaPlayer.rate), MPNowPlayingInfoPropertyPlaybackRate, nil];
if ([currentFile isAlbumTrack] && !passcodeLockEnabled) { if (artist.length > 0)
MLAlbumTrack *track = currentFile.albumTrack; [currentlyPlayingTrackInfo setObject:artist forKey:MPMediaItemPropertyArtist];
if (track.artist.length > 0) if (albumName.length > 0)
[currentlyPlayingTrackInfo setObject:track.artist forKey:MPMediaItemPropertyArtist]; [currentlyPlayingTrackInfo setObject:albumName forKey:MPMediaItemPropertyAlbumTitle];
if (track.title.length > 0) [currentlyPlayingTrackInfo setObject:[NSNumber numberWithInt:[trackNumber intValue]] forKey:MPMediaItemPropertyAlbumTrackNumber];
[currentlyPlayingTrackInfo setObject:track.title forKey:MPMediaItemPropertyTitle]; if (self.artworkImageView.image) {
if (track.album.name.length > 0) MPMediaItemArtwork *mpartwork = [[MPMediaItemArtwork alloc] initWithImage:self.artworkImageView.image];
[currentlyPlayingTrackInfo setObject:track.album.name forKey:MPMediaItemPropertyAlbumTitle]; [currentlyPlayingTrackInfo setObject:mpartwork forKey:MPMediaItemPropertyArtwork];
[currentlyPlayingTrackInfo setObject:[NSNumber numberWithInt:[track.trackNumber intValue]] forKey:MPMediaItemPropertyAlbumTrackNumber]; }
} }
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo; [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
......
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