> On Jan 7, 2017, at 3:24 PM, Charles Jenkins <cejw...@gmail.com> wrote:
> 
> I did try after you asked, and KVO may be working, but the video doesn’t 
> play. If I delete the KVO bindings from IB and change my code like this:
> 
>   var currentTime : Double = 0 {
>     didSet {
>       timeSlider.doubleValue = currentTime
>     }
>   }
> 
>   var duration: Double = 0
>   {
>     didSet {
>       timeSlider.maxValue = duration
>     }
>   }
> 
> The video will play and all the buttons will work right. Seriously, 
> *everything* works except I can’t scrub and I haven’t bothered yet to test 
> the volume slider.
> 
> If I take that working code and the ONLY changes I make are to (a) change 
> currentTime to the code below and (b) add the binding in IB, the video will 
> not play. The strange thing is when I do this, I think KVO is actually 
> working because I get hammered with log messages saying “Seek to 0.0 seconds.”
> 
>   dynamic var currentTime : Double {
>     get {
>       return CMTimeGetSeconds( player.currentTime() )
>     }
>     set ( seconds ) {
>       NSLog( "Seek to \(seconds) seconds" )
>       let time = CMTimeMakeWithSeconds( seconds, 1 )
>       player.seek( to: time )
>     }
>   }
> 
> I thought maybe this meant my periodic time observer was messed up, so I 
> replaced my equivalent of the ObjC code with this:
> 
>       myTimeObserver = player.addPeriodicTimeObserver(
>         forInterval: CMTimeMake( 1, 10 ),
>         queue: DispatchQueue.main
>       ) {
>         [weak self] ( time: CMTime ) -> () in
>         if let weakSelf = self {
>           let seconds = weakSelf.currentTime // Force a read from player
>           NSLog( "Asking to set time to \(seconds) seconds" )
>           weakSelf.currentTime = seconds // Force KVO update
>         }
>       }
> 
> And the resulting log messages prove, I think, that player.currentTime() 
> really does sit at 0.0 while I’m using KVO for the slider.

That’s odd that the currentTime variable would stay at 0.0. Have you checked 
“Continuous” for your slider in IB?

If it helps, I made a simple example project connecting a slider and Swift via 
KVO. You can drag the slider around and watch the image update as you do:

http://www.charlessoft.com/extraneous_stuff/Slider_Test 
<http://www.charlessoft.com/extraneous_stuff/Slider_Test>.zip

Charles

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to