Commit 21c45cd1 authored by Carola Nitz's avatar Carola Nitz

VLCMetaData: Populate lockscreen from mediaitem

(fixes #469)
parent 22d72dca
//
// VLCMediaPlayer + Metadata.h
// VLC
//
// Created by Carola Nitz on 9/27/17.
// Copyright © 2017 VideoLAN. All rights reserved.
//
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2017-2019 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
@class VLCMLMedia;
@interface VLCMetaData: NSObject
@property(readwrite, copy) NSString *title;
......@@ -18,5 +22,9 @@
@property(readwrite) NSNumber *elapsedPlaybackTime;
@property(readwrite) NSNumber *playbackRate;
#if TARGET_OS_IOS
- (void)updateMetadataFromMedia:(VLCMLMedia *)media mediaPlayer:(VLCMediaPlayer*)mediaPlayer;
#else
- (void)updateMetadataFromMediaPlayer:(VLCMediaPlayer *)mediaPlayer;
#endif
@end
......@@ -24,66 +24,42 @@
{
self = [super init];
if (self) {
}
return self;
}
- (void)updateMetadataFromMediaPlayer:(VLCMediaPlayer *)mediaPlayer;
{
self.trackNumber = nil;
self.title = @"";
self.artist = @"";
self.albumName = @"";
self.artworkImage = nil;
self.isAudioOnly = NO;
#if TARGET_OS_IOS
[self updateMetadataFromMediaPlayerForiOS:mediaPlayer];
#else
}
return self;
}
#if TARGET_OS_TV
- (void)updateMetadataFromMediaPlayer:(VLCMediaPlayer *)mediaPlayer;
{
[self updateMetadataFromMediaPlayerFortvOS:mediaPlayer];
#endif
}
#endif
#if TARGET_OS_IOS
- (void)updateMetadataFromMediaPlayerForiOS:(VLCMediaPlayer *)mediaPlayer
- (void)updateMetadataFromMedia:(VLCMLMedia *)media mediaPlayer:(VLCMediaPlayer*)mediaPlayer
{
MLFile *item;
if ([VLCPlaybackController sharedInstance].mediaList) {
item = [MLFile fileForURL:mediaPlayer.media.url].firstObject;
}
if (item) {
if (item.isAlbumTrack) {
self.title = item.albumTrack.title;
self.artist = item.albumTrack.artist;
self.albumName = item.albumTrack.album.name;
} else
self.title = item.title;
/* MLKit knows better than us if this thing is audio only or not */
self.isAudioOnly = [item isSupportedAudioFile];
} else {
if ([VLCKeychainCoordinator passcodeLockEnabled]) return;
if (media) {
self.title = media.title;
self.artist = media.albumTrack.artist.name;
self.trackNumber = @(media.albumTrack.trackNumber);
self.albumName = media.albumTrack.album.title;
self.artworkImage = [[UIImage alloc] initWithContentsOfFile:media.thumbnail.path];
} else { // We're streaming something
self.artworkImage = nil;
self.trackNumber = nil;
self.artist = nil;
self.albumName = nil;
[self fillFromMetaDict:mediaPlayer];
}
[self checkIsAudioOnly:mediaPlayer];
if (self.isAudioOnly) {
self.artworkImage = [VLCThumbnailsCache thumbnailForManagedObject:item];
if (self.artworkImage) {
if (self.artist)
self.title = [self.title stringByAppendingFormat:@" — %@", self.artist];
if (self.albumName)
self.title = [self.title stringByAppendingFormat:@" — %@", self.albumName];
}
if (self.title.length < 1)
self.title = [[mediaPlayer.media url] lastPathComponent];
}
[self updatePlaybackRate:mediaPlayer];
if ([VLCKeychainCoordinator passcodeLockEnabled]) return;
[self populateInfoCenterFromMetadata];
}
#else
......
......@@ -1077,7 +1077,12 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
if (_needsMetadataUpdate == NO) {
_needsMetadataUpdate = YES;
dispatch_async(dispatch_get_main_queue(), ^{
#if TARGET_OS_IOS
VLCMLMedia *media = self->_mediaPlayer.media ? [self->_delegate mediaForPlayingMedia:self->_mediaPlayer.media] : nil;
[self->_metadata updateMetadataFromMedia:media mediaPlayer:self->_mediaPlayer];
#else
[self->_metadata updateMetadataFromMediaPlayer:self->_mediaPlayer];
#endif
self->_needsMetadataUpdate = NO;
[self recoverDisplayedMetadata];
});
......
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