Commit 9562ec1a authored by Felix Paul Kühne's avatar Felix Paul Kühne

playback: stabilize and rationalize meta data retrieval

parent 55c2cdfa
......@@ -30,7 +30,7 @@
#define FORWARD_SWIPE_DURATION 30
#define BACKWARD_SWIPE_DURATION 10
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, AVAudioSessionDelegate>
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, AVAudioSessionDelegate, VLCMediaDelegate>
{
VLCMediaListPlayer *_listPlayer;
VLCMediaPlayer *_mediaPlayer;
......@@ -377,8 +377,10 @@
MLFile *item = self.mediaItem;
media = [VLCMedia mediaWithURL:[NSURL URLWithString:item.url]];
item.unread = @(NO);
} else if (!self.mediaList)
} else if (!self.mediaList) {
media = [VLCMedia mediaWithURL:self.url];
[media parse];
}
NSMutableDictionary *mediaDictionary = [[NSMutableDictionary alloc] init];
......@@ -828,38 +830,10 @@
{
VLCMediaPlayerState currentState = _mediaPlayer.state;
if (currentState == VLCMediaPlayerStateBuffering) {
/* attach delegate */
_mediaPlayer.media.delegate = self;
/* let's update meta data */
MLFile *item = self.mediaItem;
NSString *title;
NSString *artist;
NSString *albumName;
if (item) {
if (item.isAlbumTrack) {
title = item.albumTrack.title;
artist = item.albumTrack.artist;
albumName = item.albumTrack.album.name;
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaFile:item];
}
} else {
NSDictionary * metaDict = _mediaPlayer.media.metaDictionary;
if (metaDict) {
title = metaDict[VLCMetaInformationTitle];
artist = metaDict[VLCMetaInformationArtist];
albumName = metaDict[VLCMetaInformationAlbum];
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaItemWithTitle:title Artist:artist andAlbumName:albumName];
}
}
if (!self.artworkImageView.image) {
self.trackNameLabel.text = title;
self.artistNameLabel.text = artist;
self.albumNameLabel.text = albumName;
} else
self.trackNameLabel.text = [NSString stringWithFormat:@"%@ – %@ — %@", title, artist, albumName];
if (self.trackNameLabel.text.length < 1)
self.trackNameLabel.text = [[_mediaPlayer.media url] lastPathComponent];
[self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil];
[self _updateDisplayedMetadata];
}
if (currentState == VLCMediaPlayerStateError) {
......@@ -867,8 +841,9 @@
[self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
}
if ((currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) && _listPlayer.repeatMode == VLCDoNotRepeat)
[self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
if ((currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) && _listPlayer.repeatMode == VLCDoNotRepeat) {
if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == _listPlayer.mediaList.count - 1)[self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
}
UIImage *playPauseImage = [_mediaPlayer isPlaying]? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
[_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
......@@ -1258,6 +1233,52 @@
}
}
- (void)mediaDidFinishParsing:(VLCMedia *)aMedia
{
[self _updateDisplayedMetadata];
}
- (void)mediaMetaDataDidChange:(VLCMedia*)aMedia
{
[self _updateDisplayedMetadata];
}
- (void)_updateDisplayedMetadata
{
MLFile *item = self.mediaItem;
NSString *title;
NSString *artist;
NSString *albumName;
if (item) {
if (item.isAlbumTrack) {
title = item.albumTrack.title;
artist = item.albumTrack.artist;
albumName = item.albumTrack.album.name;
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaFile:item];
}
} else {
NSDictionary * metaDict = _mediaPlayer.media.metaDictionary;
if (metaDict) {
title = metaDict[VLCMetaInformationTitle];
artist = metaDict[VLCMetaInformationArtist];
albumName = metaDict[VLCMetaInformationAlbum];
self.artworkImageView.image = [VLCThumbnailsCache thumbnailForMediaItemWithTitle:title Artist:artist andAlbumName:albumName];
}
}
if (!self.artworkImageView.image) {
self.trackNameLabel.text = title;
self.artistNameLabel.text = artist;
self.albumNameLabel.text = albumName;
} else {
self.trackNameLabel.text = [NSString stringWithFormat:@"%@ – %@ — %@", title, artist, albumName];
}
if (self.trackNameLabel.text.length < 1 || [self.trackNameLabel.text isEqualToString:@" — — "])
self.trackNameLabel.text = [[_mediaPlayer.media url] lastPathComponent];
[self performSelectorInBackground:@selector(_updateExportedPlaybackInformation) withObject:nil];
}
- (void)_updateExportedPlaybackInformation
{
if (!_mediaItem) {
......
......@@ -441,9 +441,12 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
list = [[VLCMediaList alloc] init];
MLFile *file;
VLCMedia *media;
for (NSInteger x = count - 1; x > -1; x--) {
file = [(MLAlbumTrack*)tracks[x] files].anyObject;
[list addMedia:[VLCMedia mediaWithURL: [NSURL URLWithString:file.url]]];
media = [VLCMedia mediaWithURL: [NSURL URLWithString:file.url]];
[media parse];
[list addMedia:media];
}
[(VLCAppDelegate*)[UIApplication sharedApplication].delegate openMediaList:list atIndex:[tracks indexOfObject:selectedObject]];
} else
......
......@@ -12,7 +12,7 @@ CONFIGURATION="Release"
NONETWORK=no
SKIPLIBVLCCOMPILATION=no
TESTEDVLCKITHASH=86594f0a0
TESTEDVLCKITHASH=55461fb6a
TESTEDMEDIALIBRARYKITHASH=9c6382eb1
usage()
......
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