Setting Slider Value to Set SeekToTime in AVPlayer

前端 未结 2 1786
谎友^
谎友^ 2021-01-24 19:44

I am using Player library, that is using AVPlayer & AVFoundation, which is quiet convenient for my case. I successfully managed to play the video and add a slider. I set the

相关标签:
2条回答
  • 2021-01-24 19:54

    It is preferable from an UX point of view to call the seek() method on your Player after a touchUp on your slider, rather than whenever the value changes.

    As you noticed, you had poor experience with the sliderValueDidChange.

    Instead, try by adding a target/action on UIControlEvents.TouchUpInside (for instance) on your slider, then only seek. The experience should be better.

    
        var slider : UISlider! {
            didSet {
              slider.addTarget(self, action: Selector("touchUp:"), forControlEvents: [UIControlEvents.TouchUpInside])
            }
        }
    
        func touchUp(sender:AnyObject?) {
            // player.seek(slider.currentValue)
        }
    
    
    0 讨论(0)
  • 2021-01-24 19:59

    I solved my problem. I created an instance of Player so I was able to send the data from the view controller back to Player class. Then I simply applied seekToTime(). At this point, visually, it was seeming poor but then I noticed that I can use stop(), setCurrentTime() and then play() in order to make it look nicer.

    0 讨论(0)
提交回复
热议问题