iOS 允许滚动媒体栏

问题描述

所以我知道 Apple iOS 中的大多数媒体应用程序都允许用户通过认媒体界面快进。但是,它并没有更新 MPNowPlayingInfoPropertyElapsedplaybackTime 我试图弄清楚当用户向前滚动 30 秒时如何更新它。

func setupRemoteTransportControls() {
   // Get the shared MPRemoteCommandCenter
    let commandCenter = MPRemoteCommandCenter.shared()

    let changePlaybackPositionCommand = commandCenter.changePlaybackPositionCommand
    changePlaybackPositionCommand.isEnabled = true
    changePlaybackPositionCommand.addTarget { event in
            let seconds = (event as? MPChangePlaybackPositionCommandEvent)?.positionTime ?? 0
            let time = CMTime(seconds: seconds,preferredTimescale: 1)
            self.player?.seek(to: time)
            return .success
        }
    
    let skipBackwardCommand = commandCenter.skipBackwardCommand
    skipBackwardCommand.isEnabled = true
    skipBackwardCommand.addTarget(handler: skipBackward)
  
   
    let skipForwardCommand = commandCenter.skipForwardCommand
    skipForwardCommand.isEnabled = true
    skipForwardCommand.addTarget(handler: skipForward)
   
    
    
    // Add handler for Play Command
    commandCenter.playCommand.addTarget { [uNowned self] event in
        if self.player?.rate == 0.0 {
            self.player?.play()
            return .success
        }
        return .commandFailed
    }

    // Add handler for Pause Command
    commandCenter.pauseCommand.addTarget { [uNowned self] event in
        if self.player?.rate == 1.0 {
            self.player?.pause()
            return .success
        }
        return .commandFailed
    }

    
    func changePlaybackPosition(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
  
      //  self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: -30),preferredTimescale: 1))
        
       // print(CMTimeGetSeconds((self.player?.currentTime())!)) //Output: 42
        print(event)
        return .success
    }
    
    
    func skipBackward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
  
        self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: -30),preferredTimescale: 1))
        
        print(CMTimeGetSeconds((self.player?.currentTime())!)) //Output: 42

        return .success
    }

    func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
       self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: 30),preferredTimescale: 1))
        print(CMTimeGetSeconds((self.player?.currentTime())!)) //Output: 42
        
        //NowPlayingInfo[MPNowPlayingInfoPropertyElapsedplaybackTime] = CMTimeGetSeconds((self.player?.currentTime())!)
      
        
        return .success
    }
    

}

我知道我需要向 skipBackwardskipForward 添加一些东西来更新 changePlaybackPositionCommand

更新: 我相信我需要在其中添加一些内容来更新搜索栏的位置 - 有谁知道怎么做。

func skipForward(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus {
       self.player?.seek(to: CMTimeMakeWithSeconds(CMTimeGetSeconds((self.player?.currentTime())!).advanced(by: 30),preferredTimescale: 1))
        print(CMTimeGetSeconds((self.player?.currentTime())!)) //Output: 42
        
        //NowPlayingInfo[MPNowPlayingInfoPropertyElapsedplaybackTime] = CMTimeGetSeconds((self.player?.currentTime())!)
      
        
        return .success
    }
    

scrollbar

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)