StreetVoice / HysteriaPlayer

Objective-C audio player, sitting on top of AVPlayer
Other
583 stars 99 forks source link

Wrong pre-loaded time for youtube audio 140 #99

Open starlight173 opened 8 years ago

starlight173 commented 8 years ago

I extracted the audio link and get the wrong pre-loaded time. For example: this video's duration is 201s but I get 401s. How to fix that?

https://r8---sn-42u-i5ok.googlevideo.com/videoplayback?initcwndbps=2048750&dur=200.782&mime=audio%2Fmp4&sver=3&expire=1449095491&ipbits=0&mm=31&mn=sn-42u-i5ok&id=o-AHU7uLn9c8Pgo2DtWSLtAmq1HNZoH8uF-QZaTZZiLRgs&mv=m&pl=26&mt=1449073742&gir=yes&fexp=9408710%2C9416074%2C9416126%2C9417580%2C9417683%2C9418200%2C9418866%2C9420310%2C9420452%2C9421166%2C9421941%2C9421977%2C9422596%2C9422618%2C9423299%2C9423662%2C9424055%2C9424220%2C9424644%2C9424845%2C9424963&ms=au&ip=210.245.14.70&requiressl=yes&upn=mqC-Rjp5OUk&key=yt6&lmt=1394256224083111&keepalive=yes&itag=140&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&source=youtube&clen=3189562&signature=29CD06041A0E06CCC6DD587A24F4244BFE3C6C11.344FF7DDBA986CA33144B8478412B4A89F6A5F9A

saiday commented 8 years ago

Where did you get pre-loaded time? from delegate method? - (void)hysteriaPlayerCurrentItemPreloaded:(CMTime)time;

More detail required

starlight173 commented 8 years ago

Yes, that delegate. Media format: Download Audio Format: m4a Audio: Stereo, 44.1 KHz 128 Kbps Audio Format: AAC [DASH audio]

Playing audio code: self.hysteriaPlayer.removeAllItems() self.items.removeAll() self.items.append(audioURL) self.hysteriaPlayer.fetchAndPlayPlayerItem(0)

starlight173 commented 8 years ago

I found that hysteriaPlayerCurrentItemPreloaded get called 2 times when using the youtube link decoded. While with another service, only 1 time. That causes the problem.

han9over commented 8 years ago

I believe this problem is with how AVPlayer works. If you try to paste the URL in your safari and run also you will get same calculation.

If you are playing a youtube audio, I would suggest to listen for playing time and when its half of the total time, move to next song programatically.

starlight173 commented 8 years ago

@han9over : yes, so far I had to make a timer to compare and decide when should the video stopped. But think it's a litte bit hacking.

patrickjquinn commented 7 years ago

@han9over Just tested this and i'm getting the same output, incorrect duration being reported by the player, opening the link in Chrome reports the correct duration where as the player doubles it, mp4 issue doubling the of the content size means incorrect reporting of player time.

patrickjquinn commented 7 years ago

Also @gloryluu if you could share your calculation logic to compare it against my own solution to skip to the next track for efficiency it would be greatly appreciated 👍

patrickjquinn commented 7 years ago

In HysteriaPlayer.m on line 652 if you change return duration to return (duration / 2) that seems to be the neatest way to propagate the change in the most minimal fashion across the player.

patrickjquinn commented 7 years ago

You will also need a timer running a scheduled update to check which checks if the progress is duration - 0.5 in order to stop the audio and call the delegate you use to inform the UI as much.

Note that this timer should be run every 0.4 seconds and preferably on a GCD thread (In order to ensure you can catch the progress at dur - 0.5