@@ -149,7 +149,8 @@ class StreamBridge {
149149 var soundPTS : Double
150150 var videoPTS : Double
151151 var mediaDuration : Double
152-
152+ var image : MPMediaItemArtwork ?
153+
153154 var selfref : UnsafeMutableRawPointer !
154155 var player : FFPlayerViewController !
155156 var sound : AudioQueuePlayer !
@@ -434,6 +435,35 @@ class StreamBridge {
434435 }
435436 }
436437
438+ func setupArtwork( ) {
439+ var basename = remote. name
440+ var parentId = remote. parent
441+ if let subid = remote. subid, let subbase = CloudFactory . shared [ remote. storage] ? . get ( fileId: subid) {
442+ basename = subbase. name
443+ parentId = subbase. parent
444+ }
445+ var components = basename. components ( separatedBy: " . " )
446+ if components. count > 1 {
447+ components. removeLast ( )
448+ basename = components. joined ( separator: " . " )
449+ }
450+
451+ if let imageitem = CloudFactory . shared. data. getImage ( storage: remote. storage, parentId: parentId, baseName: basename) {
452+ if let imagestream = CloudFactory . shared [ remote. storage] ? . get ( fileId: imageitem. id ?? " " ) ? . open ( ) {
453+ imagestream. read ( position: 0 , length: Int ( imageitem. size) ) { data in
454+ if let data = data, let image = UIImage ( data: data) {
455+ self . image = MPMediaItemArtwork ( boundsSize: image. size) { size in
456+ return image
457+ }
458+ DispatchQueue . main. async {
459+ self . player. artworkView. image = image
460+ }
461+ }
462+ }
463+ }
464+ }
465+ }
466+
437467 func run( parent: UIViewController , onFinish: @escaping ( Int , Double ) -> Void ) {
438468 var ret = - 1
439469 var userBreak = false
@@ -499,6 +529,7 @@ class StreamBridge {
499529 }
500530 return t
501531 }
532+ setupArtwork ( )
502533 var timer1 : Timer ?
503534 DispatchQueue . main. async {
504535 UIApplication . shared. isIdleTimerDisabled = true
@@ -739,11 +770,22 @@ class StreamBridge {
739770 }
740771
741772 func updateMediaInfo( ) {
742- MPNowPlayingInfoCenter . default ( ) . nowPlayingInfo = [
743- MPMediaItemPropertyTitle: name,
744- MPNowPlayingInfoPropertyPlaybackRate: get_pause ( param) == 1 ? 0.0 : 1.0 ,
745- MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS. isNaN ? videoPTS : soundPTS,
746- MPMediaItemPropertyPlaybackDuration: mediaDuration,
747- ]
773+ if let image = image {
774+ MPNowPlayingInfoCenter . default ( ) . nowPlayingInfo = [
775+ MPMediaItemPropertyTitle: name,
776+ MPMediaItemPropertyArtwork: image,
777+ MPNowPlayingInfoPropertyPlaybackRate: get_pause ( param) == 1 ? 0.0 : 1.0 ,
778+ MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS. isNaN ? videoPTS : soundPTS,
779+ MPMediaItemPropertyPlaybackDuration: mediaDuration,
780+ ]
781+ }
782+ else {
783+ MPNowPlayingInfoCenter . default ( ) . nowPlayingInfo = [
784+ MPMediaItemPropertyTitle: name,
785+ MPNowPlayingInfoPropertyPlaybackRate: get_pause ( param) == 1 ? 0.0 : 1.0 ,
786+ MPNowPlayingInfoPropertyElapsedPlaybackTime: soundPTS. isNaN ? videoPTS : soundPTS,
787+ MPMediaItemPropertyPlaybackDuration: mediaDuration,
788+ ]
789+ }
748790 }
749791}
0 commit comments