Comments (29)
Nice one π
from react-native-video.
@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.
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.
@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.
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.
@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.
@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.
Thanks for the follow up there @jhabdas :)
from react-native-video.
@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.
@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.
@jhabdas Out of curiosity, what version of XCode & iOS are you using to develop Lumpen Radio?
from react-native-video.
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.
I ended up writing my own AudioPlayer using StreamKit and got it working.
from react-native-video.
@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.
@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.
@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.
@ericraio ended up writing my own audio player. It uses https://github.com/tumtumtum/StreamingKit
from react-native-video.
@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.
@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.
@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.
@ericraio nothing specifically I can think of. please let us know if you figure it out!
from react-native-video.
@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.
@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.
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.
@arbabi2010 did you fixed the issue in android?
from react-native-video.
@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.
@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.
@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.
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)
- [BUG]: onSeek event called instantly on Android
- [BUG]: iOS βΒ After returning to active after Mirroring, video auto-restarts HOT 1
- [BUG]: Video's not playing (black screen) specifically on iOS 17.0.2 HOT 3
- [BUG]: requireNativeComponent: "RCTVideo" was not found in the UIManager HOT 3
- [BUG]:v6 beta donβt load mp4 HOT 3
- [BUG]: v6 don't load Internet source mp4 style file,but local source mp4 and other file style can be loaded HOT 2
- Offline DRM support
- [BUG]: How do i import react native video in swift file (iOS native side) HOT 6
- [BUG]: multi audio selection HOT 2
- [BUG]: In iOS, seek is working perfect in portrait mode but when i rotate my device in landscape then on seek i am getting JSON value '0' of type NSNumber cannot be converted to NSDictionary HOT 7
- [Feature]: Privacy Manifest for Promises SDK HOT 3
- [BUG]: shutterColor not typed in Typescript HOT 3
- [BUG]: AVFoundationErrorDomain on iOS when playing .mp3 file HOT 4
- The screen turns off in fullscreen mode HOT 6
- [BUG]: codepush + RNV6, TypeError: Cannot read property 'ScaleAspectFill' of undefined HOT 3
- [Feature]: Improve error typing and management for entire react-native-video package HOT 2
- [BUG]: React Native Video Player Crashes on iOS and Apple TV with Invalid URL HOT 4
- [BUG]: After 5 to 6 seek operations the player frames starts to lag and flick.
- [BUG]: Ios single video making or repeating multiple sound HOT 5
- [BUG]: video continues playing when app goes to the background or navigate to another page HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-video.