Closed satyres closed 4 years ago
@satyres ,
1) are you playing audio or video?
2) what do you mean by "append data to the player" ?
cheers
Hi Thanks for your answser i'm playing an audio radio stream , so i'm using AVAudioPlayer , the problem is after getting some amount of data i call AVAudioPlayer and it play the data , but the problem is that the sound glitches because the AVAudioPlayer get new data here is the code : if audioData.length > 1024*100{ player = try AVAudioPlayer(data: audioData as Data, fileTypeHint: AVFileType.caf.rawValue) player?.play() } so is there a way to append the data to AVAudioPlayer after getting the first byte to be played? regards
@satyres just to be clear ..
are you in fact using CachingPlayerItem,
or, are you asking how to get started with it?
If you are already using CachingPlayerItem, everything is automatic and quite easy!
@smhk Yes i'm already using it ,and i'm getting the bytes and it records i want to play the data received and record at the same time but i can't figure it out regards
to set up your AVPlayer
let pi = CachingPlayerItem(url: .. string url .. )
pi.delegate = self
let avp = AVPlayer(playerItem: pi)
avp.automaticallyWaitsToMinimizeStalling = false
Then CPI will tell you when it is ready to play
func playerItemReadyToPlay(_ playerItem: CachingPlayerItem) {
print("cpi says READY TO PLAY")
}
then play ..
func playerItemReadyToPlay(_ playerItem: CachingPlayerItem) {
print("cpi says READY TO PLAY")
avp.play()
}
everything else is automatic. That's the whole thing.
If you have any basic questions about using AVAudioPlayer, etc, should ask on stackoverflow.com, you will get fast and complete answers. Good luck!
@smhk i've tried to play using delegate . i got the message "cpi says READY TO PLAY" but there is no sound after calling avp.play() ! am i missing something ? regards
@satyres I would strongly suggest
(1) just remove CPI from your project
(2) try getting it working normally with just AVAudioPlayer
(3) once it is working perfectly w/ AVAudioPlayer, just drop in CPI
(4) you will really have to ask on stackoverflow.com for general questions about getting AVAudioPlayer working - you can post all your code there and people are very fast/helpful
Don't forget to try playing the URL simply by dropping the URL in the browser on your laptop, to test the URL.
Good luck !
Ok i got the problem. it works ,only with file with limited data (like the example) but for live stream it doesn't work. (i mean endless data) how can i play the live data stream as soon as the buffer get filled regards
investigate
func playerItemReadyToPlay(_ playerItem: CachingPlayerItem)
good luck
Hi thank you for the hint , but i didn't figure it out. i've tried to get the data and then passed to AVAudioPlayer , i can hear sound but it stops and glitches , because i update all the data and i want to append it. AVAudioPlayer doesn't have a method to append Data , so how can we do ? playerItemReadyToPlay works only when the file has been cached , for endless stream how can we do i'm sorry but i'm totally desperate. any help please regards
simply ask on Stackoverflow! your problem does not relate to CPI. good luck !
@smhk i did already , but no answer : https://stackoverflow.com/questions/60950374/how-to-append-data-to-avaudioplayer-live-audio-stream regards
Hi i 've tried to play to data , and i found a way but the problem is that i want to append data to the player but i can't figure it out. please help regards