arielfaur / ionic-audio

An audio player for Ionic 3 and Angular 4. Works with HTML 5 audio or native audio using Cordova Media plugin.
http://arielfaur.github.io/ionic-audio/2.0/index.html
MIT License
321 stars 163 forks source link

Autoplay #174

Closed betatools closed 6 years ago

betatools commented 6 years ago

Hello

Does it have some kind of autoplay feature? I can see that your demo code has an autoplay property, but it seems it is not yet included in the source from npm

I only load one track and it would nice if the track would start automatically

arielfaur commented 6 years ago

There is a playlist feature which will play all tracks once, and then stops. Is that what you mean? The code is in the built-in sample project.

betatools commented 6 years ago

Hi Thanks for getting back to me on this. What I mean is that the audio should play when the page/component has loaded. Right now I have to press the play button to make the audio start

arielfaur commented 6 years ago

@betatools This has issues on iOS, therefore it hasn't been implemented. iOS requires a user action to trigger playback. Or at least it was the case up to recently.

shawns582 commented 6 years ago

@arielfaur Thanks for all your hard work on this plugin. I am running the demo app (with the playlist) on iOS and I am noticing that I am able to play a track in the background and when the current track ends it successfully moves on to the next track in the playlist if the app is in the foreground. If the app is in the background, the current track will end but nothing will happen until I open the app again and bring it to the foreground.

Do you have any idea why this is happening? I have the cordova-plugin-media plugin installed and have enabled background audio in XCode. My suspicion is that this has something to do with iOS, but I assume you have figured a way to enable this to work properly in the background. Can you tell me what I need to do? Thanks much!

arielfaur commented 6 years ago

@shawns582 I see your issue. I am sorry to let you down, but I haven't tried that use case although it is a very common one and should be on my list. Hopefully I can look at this issue soon!

arielfaur commented 6 years ago

@shawns582 I have been looking into this. I haven't been able to make it work. It looks like there are a number of issues on iOS 11: https://forums.developer.apple.com/thread/85415 http://debuggerdotbreak.judahgabriel.com/2016/12/13/its-almost-2017-and-html5-audio-is-still-broken-on-ios/

I even tried with native audio using the plugin, but no luck so far 👎

betatools commented 6 years ago

Hi

The “funny” thing is that the repeat function I am using works fine even though the app is in background and another app is active.

This means that when the audio file is ended, it is automatically started again. If js is disabled while in background, how could that happen?

arielfaur commented 6 years ago

@betatools Is that run running on iOS 11?

betatools commented 6 years ago

@arielfaur 11.2.1 (15C153)

I use this plugin to enable background audio. Don't know if that's got something to do with anything :)

https://github.com/EddyVerbruggen/cordova-plugin-backgroundaudio

[edit] I use html audio and not Native Audio.

arielfaur commented 6 years ago

@betatools Ha! That makes a lot of sense now 😄 Thanks for bringing that up. That's useful information!

shawns582 commented 6 years ago

@arielfaur thanks for your response ..and thanks @betatools for that info. I thought I had tried that background audio plugin but it might have been something similar but different.

I managed to get background audio working on iOS 10.3 by following this thread that makes a change to AppDelegate.m (kind of a hack but it works):

https://forum.ionicframework.com/t/using-mediaplugin-to-stream-music-how-can-i-keep-music-playing-when-switching-out-of-app-or-locking-phone/69096/2

I previously didnt have to do this so I am not sure what changed.