Comments (6)
Additional info: If I start playback of a file and take a look at the lock screen, the full duration is available even though I'm still getting updateDuration
from SwiftAudio
.
Tested on a device using iOS 13.
from swiftaudio.
I see that that the duration is available using player.duration
at some point, but when is it safe to assume it is available? What's the purpose of event updateDuration
that does not contain the total duration?
from swiftaudio.
The updateDuration
event is called whenever the AVPlayerItem changes its duration
. You can use this to know when the duration changes. If if seems to change abnormally I can take a look into it.
The class that is the source of the event is the AVPlayerItemObserver
.
To my knowledge you can assume that the player.duration
is available when the state changes to ready
from swiftaudio.
In my case, updateDuration
seems to update continuously. Looking a AVPlayerItemObserver
it seems clear why.
Code:
player.event.stateChange.addListener(self) { [weak self] state in
if ["ready", "playing"].contains(state.rawValue) {
print("⌛ stateChange (to ready, playing) - player.duration: \(self?.player.duration)")
}
}
player.event.updateDuration.addListener(self) { [weak self] duration in
print("⌛ updateDuration: \(duration)")
}
Output:
⌛ stateChange (to ready, playing) - player.duration: Optional(1246.4848979591836)
⌛ updateDuration: 0.4963265306122449
⌛ updateDuration: 30.48307925
⌛ updateDuration: 67.341854761
⌛ updateDuration: 122.643079251
⌛ updateDuration: 158.822671088
⌛ updateDuration: 196.360630272
⌛ updateDuration: 233.245528232
⌛ updateDuration: 270.104303743
⌛ updateDuration: 306.963079254
⌛ updateDuration: 343.821854765
⌛ updateDuration: 380.680630276
⌛ updateDuration: 417.565528236
⌛ updateDuration: 454.424303747
⌛ updateDuration: 509.725528237
⌛ updateDuration: 546.584303748
⌛ updateDuration: 583.443079259
⌛ updateDuration: 637.359813954
⌛ updateDuration: 674.923895587
⌛ updateDuration: 711.782671098
⌛ updateDuration: 748.641446609
⌛ updateDuration: 803.942671099
⌛ updateDuration: 840.122262936
⌛ updateDuration: 877.66022212
⌛ updateDuration: 929.565528244
⌛ updateDuration: 965.745120081
⌛ updateDuration: 1002.603895592
⌛ updateDuration: 1039.462671103
⌛ updateDuration: 1076.321446614
⌛ updateDuration: 1111.821854778
⌛ updateDuration: 1168.481446615
⌛ updateDuration: 1205.340222126
⌛ updateDuration: 1246.4848979591836
I tried using player.duration
when state changes to ready
, but if you pass playWhenReady: true
, state goes directly from loading
to playing
, never entering ready
state. A workaround is to access player.duration
when state changes to ready
or playing
, but that is not optimal.
from swiftaudio.
The updateDuration
seems to work as intended, it is only intended to send events whenever the item updates its duration value. Does your scrub behave better with your PR #87 and using the player's ready state?
As for the incorrect state, that is interesting and definitely seems like a bug 🐛You can move it to a separate ticket and I will do some testing too 👍
from swiftaudio.
With the PR, I can access player.duration
when ready
and scrubbing works perfectly :)
I don't think I completely understand the updateDuration
event though, if it's working as intended. Why does it emit intermediate duration values up until the final full duration when the full duration it is already on ready
?
from swiftaudio.
Related Issues (20)
- Skipforward and skipforward issue HOT 5
- Set preferredPeakBitRate
- Catch Expired Auth Token to modify headers HOT 1
- Player state not updated after triggering the play()
- Cannot run Example app HOT 1
- How to know that the song is ended HOT 1
- AVQueuePlayer for gapless audio
- Regarding stop button functionality HOT 15
- QueuedAudioPlayer.reset() is not accessible due to 'internal' protection level
- Not working with local file in Queue HOT 1
- Load the audio player
- MPRemoteCommandCenter
- handleAudioPlayerStateChange call multiple time HOT 1
- how to clearQueue HOT 2
- .wav file not play
- Repository Future HOT 2
- @available enum issue on XCode 13 HOT 2
- iOS 15 can not play music in the background HOT 6
- Song will not play if it contains any character between "èéêëēėęàáâäæãåāîïíīįìôöòóœøōõûüùúū"
- Xcode 12.5 - Using 'class' keyword for protocol inheritance is deprecated; use 'AnyObject' instead
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftaudio.