nstudio / nativescript-audio

:microphone: NativeScript plugin to record and play audio :musical_note:
Other
150 stars 104 forks source link

Enhancement: Use AVPlayer on iOS for streaming files #99

Open jayvolr opened 6 years ago

jayvolr commented 6 years ago

I'm trying to play audio from multiple URLs of live audio streams. It works just fine on android, but iOS is giving me trouble.

I've created a minimal nativescript app with steps in the README.md to easily reproduce this:

https://github.com/jayvolr/nativescript-audio-stream-error

jayvolr commented 6 years ago

To clarify, I'm not trying to play multiple streams at once, there's just multiple URLs which have this issue on iOS (anything live and not pre-recorded).

jayvolr commented 6 years ago

This answer on StackOverflow seems like it might be related: https://stackoverflow.com/a/34563570

It's not dealing with NativeScript, but the poster says "Use AVPlayer instead of AVAudioPlayer to play remote content. As per documentation AVAudioPlayer needs mp3 file to play Audio. AVAudioPlayer not provide support for streaming."

nativescript-audio uses AVAudioPlayer, correct?

bradmartin commented 6 years ago

That is correct. See here for the implementation. Could try switching the player implementation out with https://developer.apple.com/documentation/avfoundation/avplayer class. I don't know the time/work involved. Would depend if it would be necessary to switch out the entire audio player on iOS or if some internal work could be done to us AVPlayer just for remote content and leave the current class working on local files.

7ammer commented 6 years ago

+1 If you get the time this would be awesome :)

janstoeckler commented 5 years ago

This https://github.com/janstoeckler/nativescript-audio/tree/ios-avplayer-reroll is a "reroll" of sorts of the ios-avplayer against the current master w/ just the necessary changes to ios/player.ts, don't know if that's helpful or not, but it seems to work.

bradmartin commented 5 years ago

I have this done locally, just need to handle merging the changes and not causing too many issues/breaking changes.

7ammer commented 5 years ago

Hello @janstoeckler, I have tried pulling in your fork but unfortunately doing the below returns null. Android works fine though.

import { TNSPlayer } from '/path/to/local/copy/of/janstoeckler/nativescript-audio/ios-avplayer-reroll';

let player = new TNSPlayer();
console.log(player); // returns null

I wondered if you knew what was wrong?

Thanks


nativescript version:5.4.2

bradmartin commented 5 years ago

this plugin will be the future work of playing audio files https://github.com/nstudio/nativescript-audio-player It uses AVPlayer, has no built in recording as splitting the plugins made more sense overall to us going forward. We haven't had time to tidy up the documentation or API on it but it should work very similar to this plugin as it was copy/paste with some tweaks and changes.

7ammer commented 5 years ago

@bradmartin That's great! Thank you 👍 I'll check it out and let you know if I run into anything.

Many thanks again! :)

7ammer commented 4 years ago

Any updates? nstudio/nativescript-audio-player is looking a bit dead :L

felixkrautschuk commented 2 weeks ago

Did anyone find a solution for that?