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

VLCMetaData: Populate lockscreen from mediaitem

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