Commit 2848a7dd authored by Carola Nitz's avatar Carola Nitz

VLCMetaData: split methods for iOS and tvOS for readability

parent 37ade212
//
// VLCMediaPlayer + Metadata.m
// VLC
//
// Created by Carola Nitz on 9/27/17.
// Copyright © 2017 VideoLAN. All rights reserved.
//
/*****************************************************************************
* VLC for iOS
*****************************************************************************
* Copyright (c) 2017 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Carola Nitz <caro # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCMetadata.h"
#import <MediaPlayer/MediaPlayer.h>
......@@ -27,19 +30,26 @@
- (void)updateMetadataFromMediaPlayer:(VLCMediaPlayer *)mediaPlayer;
{
#if TARGET_OS_IOS
MLFile *item;
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];
#endif
}
#if TARGET_OS_IOS
- (void)updateMetadataFromMediaPlayerForiOS:(VLCMediaPlayer *)mediaPlayer
{
MLFile *item;
if ([VLCPlaybackController sharedInstance].mediaList) {
NSArray *matches = [MLFile fileForURL:mediaPlayer.media.url];
item = matches.firstObject;
item = [MLFile fileForURL:mediaPlayer.media.url].firstObject;
}
if (item) {
......@@ -53,19 +63,54 @@
/* MLKit knows better than us if this thing is audio only or not */
self.isAudioOnly = [item isSupportedAudioFile];
} else {
#endif
NSDictionary * metaDict = mediaPlayer.media.metaDictionary;
[self fillFromMetaDict:mediaPlayer];
}
[self checkIsAudioOnly:mediaPlayer];
if (metaDict) {
self.title = metaDict[VLCMetaInformationNowPlaying] ? metaDict[VLCMetaInformationNowPlaying] : metaDict[VLCMetaInformationTitle];
self.artist = metaDict[VLCMetaInformationArtist];
self.albumName = metaDict[VLCMetaInformationAlbum];
self.trackNumber = metaDict[VLCMetaInformationTrackNumber];
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 TARGET_OS_IOS
if (self.title.length < 1)
self.title = [[mediaPlayer.media url] lastPathComponent];
}
[self updatePlaybackRate:mediaPlayer];
if ([VLCKeychainCoordinator passcodeLockEnabled]) return;
[self populateInfoCenterFromMetadata];
}
#else
- (void)updateMetadataFromMediaPlayerFortvOS:(VLCMediaPlayer *)mediaPlayer
{
[self fillFromMetaDict:mediaPlayer];
[self checkIsAudioOnly:mediaPlayer];
if (self.isAudioOnly) {
if (self.title.length < 1)
self.title = [[mediaPlayer.media url] lastPathComponent];
}
[self updatePlaybackRate:mediaPlayer];
[self populateInfoCenterFromMetadata];
}
#endif
- (void)updatePlaybackRate:(VLCMediaPlayer *)mediaPlayer
{
self.playbackDuration = @(mediaPlayer.media.length.intValue / 1000.);
self.playbackRate = @(mediaPlayer.rate);
self.elapsedPlaybackTime = @(mediaPlayer.time.value.floatValue / 1000.);
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
}
- (void)checkIsAudioOnly:(VLCMediaPlayer *)mediaPlayer
{
if (!self.isAudioOnly) {
/* either what we are playing is not a file known to MLKit or
* MLKit fails to acknowledge that it is audio-only.
......@@ -80,29 +125,18 @@
}
}
}
}
if (self.isAudioOnly) {
#if TARGET_OS_IOS
self.artworkImage = [VLCThumbnailsCache thumbnailForManagedObject:item];
- (void)fillFromMetaDict:(VLCMediaPlayer *)mediaPlayer
{
NSDictionary *metaDict = mediaPlayer.media.metaDictionary;
if (self.artworkImage) {
if (self.artist)
self.title = [self.title stringByAppendingFormat:@" — %@", self.artist];
if (self.albumName)
self.title = [self.title stringByAppendingFormat:@" — %@", self.albumName];
}
#endif
if (self.title.length < 1)
self.title = [[mediaPlayer.media url] lastPathComponent];
if (metaDict) {
self.title = metaDict[VLCMetaInformationNowPlaying] ?: metaDict[VLCMetaInformationTitle];
self.artist = metaDict[VLCMetaInformationArtist];
self.albumName = metaDict[VLCMetaInformationAlbum];
self.trackNumber = metaDict[VLCMetaInformationTrackNumber];
}
self.playbackDuration = @(mediaPlayer.media.length.intValue / 1000.);
self.playbackRate = @(mediaPlayer.rate);
self.elapsedPlaybackTime = @(mediaPlayer.time.value.floatValue / 1000.);
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
#if TARGET_OS_IOS
if ([VLCKeychainCoordinator passcodeLockEnabled]) return;
#endif
[self populateInfoCenterFromMetadata];
}
- (void)populateInfoCenterFromMetadata
......
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