noreasonprojects / ModernAVPlayer

ModernAVPlayer is a persistence AVPlayer wrapper
MIT License
282 stars 46 forks source link

ModernAVPlayer and SwiftUI #164

Closed AminMahpour closed 4 years ago

AminMahpour commented 4 years ago

Hi Raphrel,

Thanks for developing such an easy to use yet powerful package for Swift.

I am using your package to prototype an ios app using SwiftUI. Everything is working fine except the "duration" of the track. I can't find a way to retrieve this information from the player.

Any help is appreciated. Thanks, Amin

AminMahpour commented 4 years ago

I got it working but it might not be the most elegant way to do it:

let pubSubj = thisplayer.rx.itemDuration

pubSubj.subscribe(
{
self.duration = $0.event.element!!
})
raphrel commented 4 years ago

check out Rx examples in Demo App, you'll find another way to get it.

otherwise this syntax may be better for you ? (don't forget the onNext parameter)

player.rx.itemDuration.subscribe(onNext: { duration in
     // duration is Double? and accessible here
})

also, don't forget to dispose.