indiecastfm / react-native-audio-streamer

A react-native audio streaming module which works on both iOS & Android
MIT License
132 stars 50 forks source link

Background streaming and controls? #1

Closed jasongrishkoff closed 7 years ago

jasongrishkoff commented 7 years ago

Hey Victor, been building a React Native audio app for a little while now, and every library I've bumped into struggles with background streaming + control (eg, playing next song while in background; lock screen controls).

Have you put any thought into these functions?

victor36max commented 7 years ago

Hi Jason,

I made this module only for bridging iOS & Android audio streaming into a set of react-native api. However this module should play well together with RN modules that specifically handles background controls. You can look at this project

I think it is the closest thing to what you want to achieve, and it probably will completely support Android in the next release (see the pull request)

jasongrishkoff commented 7 years ago

Cool yep, have played with that project a bit. Just got your library set up last night and it's running smooth as butter -- way more efficient than the one I was using. Thanks!

Next step on my side is to explore how to trigger "next" when a song finishes while app is backgrounded. Will update if I figure that out :)

jasongrishkoff commented 7 years ago

Been playing with the React Native Music Control project you linked. Seems promising! Still smashing my head against the wall on the main problem though: how to initiate a "playNext()" function when the current song has ended while app is backgrounded.

mahmoudfelfel commented 7 years ago

hey @jasongrishkoff, have you figured out that issue of continuous background play of audio files, I have the same issue. Also I checked your apps (Indie shuffle apps) are these in react native? I'm building an audio player app as well, which libraries for audio player would you recommend in react native, I tried many and each one has some missing features. Thanks

jasongrishkoff commented 7 years ago

Hey Mahmoud, both of the current Indie Shuffle apps were built natively with contracted help. I'm trying to take things into my own hands :)

So far, no luck getting background functions to fire. I think the only solution will be to build a native component for the audio function and send everything that way. But... yeah, no experience there haha.

victor36max commented 7 years ago

@jasongrishkoff is the playNext() problem happening in ios/android or both?

on the app i'm working on right now (mainly testing on ios first), I've done the following and the background playing is fine (play, pause, next & previous)

jasongrishkoff commented 7 years ago

I'm only testing in Android right now, so we're opposite :)

What is "audio background mode"?

Using RNAudioStreamer to observe state change only works for me if the app is in the foreground, because I'm running it from a React Native component. And as soon as the React Native app is backgrounded (eg, I start using Chrome or go into Messenger), the app becomes unresponsive. Once the song starts playing, the only way to get it to "playNext()" is by re-opening the app, at which point it does so instantly.

victor36max commented 7 years ago

@jasongrishkoff thanks for telling me, I will test it on android and get back to you

jasongrishkoff commented 7 years ago

Cool. Just to be extra clear -- the song continues to play when the app is backgrounded. It's just that once the song ends, I can't trigger my "nextSong()" function to move to the next song in my playlist. I think that needs to be done natively, because React Native can only run / execute code when it's in the foreground.

jasongrishkoff commented 7 years ago

Heyo, so just an update: this actually plays quite nicely with React Native Music Control. I'm able to listen to the RNAudioStreamer.status() method to detect when a song is "FINISHED" and then fire off the next song in my code.

This was a bit more complicated with the app in background, though. So, what I did was create a Headless Task in the android folder called NotificationService.java. When the RNAudioStreamerModule hits ExoPlayer.STATE_ENDED, I fire an Intent for the NotificationService which kicks the React Native app back into gear and fires off that next song.

I'm not sure that's the smoothest way, but it (mostly) works...

victor36max commented 7 years ago

Sorry for late response. I would like to invite @rikochet for Android questions

livelyjp commented 7 years ago

Hi, was a solution found for continuing background streaming when the app is not in the foreground? Ran into this problem when setting up 'react-native-music-control'.

Thanks in advance

jasongrishkoff commented 7 years ago

It should actually work well with both of those, no work required. Ware you on iOS or Android?