From eefae42607e0de5bb62274bde7dafc9749b82881 Mon Sep 17 00:00:00 2001 From: lithium03 Date: Fri, 22 Nov 2019 03:39:53 +0900 Subject: [PATCH] v1.4.2(56) Add artwork image on ffplayer --- .../project.pbxproj | 4 +- ffplayer/ffplayer/player.swift | 56 ++++++++++++++++--- ffplayer/ffplayer/playerView.swift | 13 ++++- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj b/ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj index 8a39c97..fcecb74 100644 --- a/ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj +++ b/ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj @@ -813,7 +813,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = 7A9X38B4YU; "ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES; @@ -848,7 +848,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = ccViewer/ccViewer.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER = YES; DEVELOPMENT_TEAM = 7A9X38B4YU; "ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES; diff --git a/ffplayer/ffplayer/player.swift b/ffplayer/ffplayer/player.swift index be5b6d2..b2e4472 100644 --- a/ffplayer/ffplayer/player.swift +++ b/ffplayer/ffplayer/player.swift @@ -149,7 +149,8 @@ class StreamBridge { var soundPTS: Double var videoPTS: Double var mediaDuration: Double - + var image: MPMediaItemArtwork? + var selfref: UnsafeMutableRawPointer! var player: FFPlayerViewController! var sound: AudioQueuePlayer! @@ -434,6 +435,35 @@ class StreamBridge { } } + func setupArtwork() { + var basename = remote.name + var parentId = remote.parent + if let subid = remote.subid, let subbase = CloudFactory.shared[remote.storage]?.get(fileId: subid) { + basename = subbase.name + parentId = subbase.parent + } + var components = basename.components(separatedBy: ".") + if components.count > 1 { + components.removeLast() + basename = components.joined(separator: ".") + } + + if let imageitem = CloudFactory.shared.data.getImage(storage: remote.storage, parentId: parentId, baseName: basename) { + if let imagestream = CloudFactory.shared[remote.storage]?.get(fileId: imageitem.id ?? "")?.open() { + imagestream.read(position: 0, length: Int(imageitem.size)) { data in + if let data = data, let image = UIImage(data: data) { + self.image = MPMediaItemArtwork(boundsSize: image.size) { size in + return image + } + DispatchQueue.main.async { + self.player.artworkView.image = image + } + } + } + } + } + } + func run(parent: UIViewController, onFinish: @escaping (Int, Double)->Void) { var ret = -1 var userBreak = false @@ -499,6 +529,7 @@ class StreamBridge { } return t } + setupArtwork() var timer1: Timer? DispatchQueue.main.async { UIApplication.shared.isIdleTimerDisabled = true @@ -739,11 +770,22 @@ class StreamBridge { } func updateMediaInfo() { - MPNowPlayingInfoCenter.default().nowPlayingInfo = [ - MPMediaItemPropertyTitle: name, - MPNowPlayingInfoPropertyPlaybackRate: get_pause(param) == 1 ? 0.0: 1.0, - MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS.isNaN ? videoPTS : soundPTS, - MPMediaItemPropertyPlaybackDuration: mediaDuration, - ] + if let image = image { + MPNowPlayingInfoCenter.default().nowPlayingInfo = [ + MPMediaItemPropertyTitle: name, + MPMediaItemPropertyArtwork: image, + MPNowPlayingInfoPropertyPlaybackRate: get_pause(param) == 1 ? 0.0: 1.0, + MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS.isNaN ? videoPTS : soundPTS, + MPMediaItemPropertyPlaybackDuration: mediaDuration, + ] + } + else { + MPNowPlayingInfoCenter.default().nowPlayingInfo = [ + MPMediaItemPropertyTitle: name, + MPNowPlayingInfoPropertyPlaybackRate: get_pause(param) == 1 ? 0.0: 1.0, + MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS.isNaN ? videoPTS : soundPTS, + MPMediaItemPropertyPlaybackDuration: mediaDuration, + ] + } } } diff --git a/ffplayer/ffplayer/playerView.swift b/ffplayer/ffplayer/playerView.swift index 42eb4f8..b8380ef 100644 --- a/ffplayer/ffplayer/playerView.swift +++ b/ffplayer/ffplayer/playerView.swift @@ -27,6 +27,7 @@ public class FFPlayerViewController: UIViewController { var progressView: UIProgressView! var slider: UISlider! var imageView: UIImageView! + var artworkView: UIImageView! var button_close: UIButton! var play_image: UIImage! var pause_image: UIImage! @@ -80,7 +81,17 @@ public class FFPlayerViewController: UIViewController { if bsec > 0 { skip_prevsec = bsec } - + + artworkView = UIImageView() + artworkView.contentMode = .scaleAspectFit + view.addSubview(artworkView) + + artworkView.translatesAutoresizingMaskIntoConstraints = false + artworkView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true + artworkView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true + artworkView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true + artworkView.heightAnchor.constraint(equalTo: view.heightAnchor).isActive = true + imageView = UIImageView() imageView.contentMode = .scaleAspectFit view.addSubview(imageView)