Skip to content

Commit

Permalink
v1.4.2(56)
Browse files Browse the repository at this point in the history
Add artwork image on ffplayer
  • Loading branch information
lithium0003 committed Nov 21, 2019
1 parent c47f16b commit eefae42
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ccViewer/CryptCloudViewer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 49 additions & 7 deletions ffplayer/ffplayer/player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -499,6 +529,7 @@ class StreamBridge {
}
return t
}
setupArtwork()
var timer1: Timer?
DispatchQueue.main.async {
UIApplication.shared.isIdleTimerDisabled = true
Expand Down Expand Up @@ -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,
]
}
}
}
13 changes: 12 additions & 1 deletion ffplayer/ffplayer/playerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eefae42

Please sign in to comment.