GithubHelp home page GithubHelp logo

Comments (29)

brentvatne avatar brentvatne commented on April 28, 2024 3

Nice one πŸ˜„

from react-native-video.

 avatar commented on April 28, 2024 3

@jamesfzhang Did you remember to set up your app for background playback in Info.plist?

<dict>
    <key>UIBackgroundModes</key>
    <array>
        <string>audio</string>
    </array>
</dict>

For a working example of background playback using the above code snippets please feel free to study the source of my Lumpen Radio app.

from react-native-video.

 avatar commented on April 28, 2024 2

Background playback can be achieved by adding the following to your AppDelegate, ViewController or other suitable class and updating the Info.plist file for background playback:

@import AVFoundation

- (void)setSharedAudioSessionCategory
{
  NSError *categoryError = nil;
  [[AVAudioSession sharedInstance]
    setCategory:AVAudioSessionCategoryPlayback
          error:&categoryError];
  if (categoryError) {
    NSLog(@"Error setting category!");
  }
}

In my project I used the above in my AudioManager class and it worked well for background playback. It's could be problematic if this kind of code was added to a React Native Module as it could conflict with the app's actual intentions, and some component authors might define things differently making modules problematic to mix-and-match within an app.

from react-native-video.

ericraio avatar ericraio commented on April 28, 2024 1

@jhabdas The way I know get the airplay icon to display is you need to use iOS's MPVolumeView and if AirPlay is enabled for the app, the icon will appear next to the slider. Now I think you can disable the slider from displaying but I am not sure.

When Spotify displays the AirPlay icon, I think they render it out and create their own custom element that delegates the event to the airplay icon to trigger the menu.

(fun fact, I was working at Sony with PlayStation Music & Spotify)

from react-native-video.

johanneslumpe avatar johanneslumpe commented on April 28, 2024

Did you try to implement the proper background mode for your application? I didn't test it, but theoretically it should work when you add the correct background mode for playing audio to your plist.

from react-native-video.

 avatar commented on April 28, 2024

@crysfel take a look at StreamingKit for playing audio. It can be installed as a CocoaPod and wired up to play audio over HTTP, backgrounded and locked, and manage audio session interruptions (e.g. incoming calls, Siri and headphone unplug). You should then be able to use the ReaCT bridge to dispatch events to control your video from there using the public API currently in development.

Functional example with detailed commits here (URL subject to change):
https://github.com/jhabdas/react-native-es6-reflux

from react-native-video.

tmoreton avatar tmoreton commented on April 28, 2024

@crysfel I'm doing something similar, were you able to figure out how to play audio in the background using the react-native-video component or did you have to switch to the SteamingKit mentioned

from react-native-video.

brentvatne avatar brentvatne commented on April 28, 2024

Thanks for the follow up there @jhabdas :)

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

@jhabdas I added the code snippet you wrote above to my AppDelegate and followed these instructions on enabling Background playback. But I still can't get audio to play in the background.

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

@jhabdas Yes I did update Info.plist. I was hoping to avoid having to learn Objective C as I wanted to get this app I'm working on out ASAP, but thanks for the help. I'll check it out.

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

@jhabdas Out of curiosity, what version of XCode & iOS are you using to develop Lumpen Radio?

from react-native-video.

jasecoop avatar jasecoop commented on April 28, 2024

Thanks for your help with this @jhabdas.

I'm afraid, like @jamesfzhang, I haven't been able to get this working.

I don't have an AudioClass, where should I put that snippet of code?

James, did you get it working in the end?

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

I ended up writing my own AudioPlayer using StreamKit and got it working.

from react-native-video.

 avatar commented on April 28, 2024

@jamesfzhang are you open source by any chance? πŸ‘Ό be great to see a few more audio implementations so we could look at creating an audio native module on top of StreamingKit (or similar), possibly using something like rem.

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

@jhabdas Unfortunately it is not since it was written for a client. But I would be interested in contributing to a generic full-featured audio player (unlike https://github.com/andreaskeller/react-native-audioplayer)

from react-native-video.

ericraio avatar ericraio commented on April 28, 2024

@jamesfzhang did you ever find a full feature generic audio player? This video lib is the only one that works for me

from react-native-video.

jamesfzhang avatar jamesfzhang commented on April 28, 2024

@ericraio ended up writing my own audio player. It uses https://github.com/tumtumtum/StreamingKit

from react-native-video.

jasecoop avatar jasecoop commented on April 28, 2024

@jamesfzhang any chance we could see an example of this in use? I have good experience with react-native but am at a loss when it gets to objective c. This issue a real blocker on my project atm

from react-native-video.

 avatar commented on April 28, 2024

@jasecoop StreamingKit at work in OSS form. README contains links to
slides, posts and a Webcast I gave explaining how it all works. Hope it
helps. Good luck!

https://github.com/jhabdas/lumpen-radio
On Thu, Mar 31, 2016 at 1:12 AM jasecoop [email protected] wrote:

@jamesfzhang https://github.com/jamesfzhang any chance we could see an
example of this in use? I have good experience with react-native but am at
a loss when it gets to objective c. This issue a real blocker on my project
atm

β€”
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#41 (comment)

from react-native-video.

ericraio avatar ericraio commented on April 28, 2024

@jhabdas thanks for contributing all of this! I have a quick question about in lumpen radio. What did you do for AirPlay support?

I am also looking to add an airplay button and allow you to switch the audio to a device like AppleTV

from react-native-video.

 avatar commented on April 28, 2024

@ericraio nothing specifically I can think of. please let us know if you figure it out!

from react-native-video.

ericraio avatar ericraio commented on April 28, 2024

@jhabdas hey good news! When background audio is turned on in xcode which also includes airplay,
after I installed this library, the airplay icon gets displayed.

https://github.com/IFours/react-native-volume-slider

from react-native-video.

 avatar commented on April 28, 2024

@ericraio did the author bundle the AirPlay icon with the slider module so it shows in the UI and not simply the system menus? how does the experience compare to, say, Spotify, if you've used it?

from react-native-video.

arbabi2010 avatar arbabi2010 commented on April 28, 2024

Hi. I want to do this on android. How can i use it? I set "playInBackground:true" but not working properly

from react-native-video.

sibigit avatar sibigit commented on April 28, 2024

@arbabi2010 did you fixed the issue in android?

from react-native-video.

arbabi2010 avatar arbabi2010 commented on April 28, 2024

@arbabi2010 did you fixed the issue in android?

Yes. but with some other packages .
I use this tutorial . and i changed some codes on it
https://reactnativeexample.com/audio-player-to-offline-local-and-online-streaming-audio/

from react-native-video.

sibigit avatar sibigit commented on April 28, 2024

@arbabi2010 did you fixed the issue in android?

Yes. but with some other packages .
I use this tutorial . and i changed some codes on it
https://reactnativeexample.com/audio-player-to-offline-local-and-online-streaming-audio/

@arbabi2010 Thanks for replay,can you able to give the changed codes for play the sound when mobile in locked mode

from react-native-video.

AbhijeetGiram avatar AbhijeetGiram commented on April 28, 2024

@crysfel
I have found one workaround for android which allows you to prevent the screen from going to sleep while your app is active. I have used it for audio and it works for me with the help of react-native-keep-awake module.

https://www.npmjs.com/package/react-native-keep-awake

from react-native-video.

AbhijeetGiram avatar AbhijeetGiram commented on April 28, 2024

I have found the way which allows you to play the track even when screen goes to sleep/locked. I have used @react-native-community/audio-toolkit to implement the same.

e.g.
soundOne = new Player('sound_example.mp3', { continuesToPlayInBackground: true });

Here's the link!
https://www.npmjs.com/package/@react-native-community/audio-toolkit

Thanks!

from react-native-video.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.