Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to implement autoplay??? #189

Open
outoftheboxbz opened this issue Mar 31, 2018 · 5 comments
Open

Is there a way to implement autoplay??? #189

outoftheboxbz opened this issue Mar 31, 2018 · 5 comments

Comments

@outoftheboxbz
Copy link

The plugin works well for me. I also have it working along with ionic music controls and background mode. Just wanted to know if there is a way to allow my audio to autoplay

@rdai
Copy link

rdai commented Apr 10, 2018

Maybe you can put some code in onTrackFinished function to look for the next item in this._audioProvider.tracks array?

@codinronan
Copy link

You can't do this via ionic audio, period. This is not an issue with this fantastic library; rather the problem is with the devices. Even if you implement something like the above you will run into the following:

  1. On Android, without a WAKE_LOCK, your device will go to sleep mid-song and you can't wake it up programmatically. You can solve that one simply by adding the WAKE_LOCK permission to your app. Even still, you will run into issues such as no control over the buffering behavior, stuttering on bad connections, etc. On most older Android devices, HTML5 audio and the native audio track both wait until most of the song is downloaded to begin playback. On Android API < 23, the CoreAudio implementation actually waits for the entire song, which is a terrible user experience.

  2. iOS is more insidious. Whether you use the WebAudioTrack or CordovaAudioTrack, iOS intentionally cripples both of them to not be able to continue playing once a song ends. Period. It maintains something called an audio session, and the session ends once a song completes; even if you attempt to keep the session alive, the OS knows that you tried to start a song without user interaction and prevents playback. You cannot fix this via ionic-audio nor cordova-plugin-media.

Because of this I have created a new cordova plugin, called cordova-plugin-playlist that resolves both of the above issues. On Android it uses Google's own ExoPlayer, which has far superior playback and buffering capabilities, and on iOS it uses the AVQueuePlayer, which is specially designed to allow continuous playback of discontinuous audio sources.

In the UI I still use ionic-audio as the interface to controls, I just shim the commands back into my plugin. I suppose I could actually make the tracks directly compatible so you can pass them into this library's controls.

I won't link to it here out of respect for arielfaur, I have used his work for almost 2 years and love it. If you're interested it is on npm.

@arielfaur
Copy link
Owner

@codinronan Thanks for the kind words and please go ahead and post the link to the plugin. It is great that you found a way to overcome those OS limitations.
On the other hand, I am having trouble with the definition of autoplay which can have several meanings depending on the context. It could mean to start playback automatically upon app launch, or it could also mean to automatically skip to the next song. The playlist use case is the one I have coded in the built-in demo, although it seems some people are still having trouble making it work.

@sansopheakh
Copy link

@codinronan Thanks for the kind words and please go ahead and post the link to the plugin. It is great that you found a way to overcome those OS limitations.
On the other hand, I am having trouble with the definition of autoplay which can have several meanings depending on the context. It could mean to start playback automatically upon app launch, or it could also mean to automatically skip to the next song. The playlist use case is the one I have coded in the built-in demo, although it seems some people are still having trouble making it work.

@arielfaur i'm looking for the code to start play the sound automatically upon app launch also.
If you resolved please alert me. Thank bro.

@arielfaur
Copy link
Owner

@sansopheakh Sorry, I haven't been able to keep up with this lately. Hope I can release a new version soon.
Contributors are welcome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants