johnsonsu / react-native-sound-player Goto Github PK
View Code? Open in Web Editor NEWPlay sound file in ReactNative
License: MIT License
Play sound file in ReactNative
License: MIT License
I've writing about using this library, but without a tagged release I have to tell readers to depend on dev master. It would be awesome if there was a tag I could point them to (even if it was a 0.1.0
tag)...
Are there plans for updates on playing online audio files from network? I really like this library, it's super easy to implement, and this feature would make it a lot better
How can I change the state inside the getInfo()-method? Insteed of showing duration:.... currenttime:..., I just want to get currentTime in the state. This is my code. this.setState({seconds: info}) doesnt work..
async getInfo() {
try {
const info = await SoundPlayer.getInfo();
this.setState({seconds: info})
console.log("info", info);
} catch (e) {
console.log("There is no song playing", e);
}
}
SoundPlayer.onFinishedLoading(this.loadedSound);
loadedSound(data) {
console.log(data); --> always true
}
doesn't wait to load and is triggering the event straight away and is always loaded with success.
never received and error.
I want to show a bar of the current progress of playing my file from a URL:
const listener = SoundPlayer.addEventListener(
'FinishedLoadingURL',
async result => {
const info = await SoundPlayer.getInfo()
Animated.timing(playingAnimationValue.current, {
toValue: 100,
duration: info.duration * 1000
}).start()
}
)
Unfortunately there's a delay between FinishedLoadingURL
and the file actually being played. How can I resolve this without having an artificial delay?
Thanks!
edit: Seems to be more a problem on iOS than Android
While it works on Android and on the iOS emulator, on an actual iPhone, audio won’t play when the app is in the background.
We currently have half of what we need to have a seek-able progress bar (the meta info for how long a song is and what the current position is), but no way to move to somewhere in the middle of the song.
Thanks for the great library, But, After added this library, It is playing only song, But, No controls showing in UI.
How to enable the controls in UI?
Hi! I'm currently using react-native-sound but I'm finding it really hard to work with as it's a lot of bugs and I'm thinking about switching over to this one. Is there any way to add a way to loop sounds? I want to have some background music that loops in the background.
Thanks in advance!
have:
"react": "16.8.6",
"react-native": "0.60.0",
"react-native-sound": "0.10.12",
have done npm i
then running a project but receiving the error:
Cannot read property 'IsAndroid' of undefined
consoling inside of file 'sound.js' of package
and this is true, there are no RNSound
pod install
returns me:
[!] CocoaPods could not find compatible versions for pod "React/Core":
In Podfile:
RNSound (from `/Users/antongoncharov/Development/hearingapp/node_modules/react-native-sound`) was resolved to 0.10.12, which depends on
React/Core
None of your spec sources contains a spec satisfying the dependency: `React/Core`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
no podspec found for react-native-sound-player
It would be neat if there was an option to keep the device's screen from switch off while playing music. Currently, I am using https://github.com/corbt/react-native-keep-awake to do this. Perhaps it's not the sort of thing you want this library to do (and I completely understand that). I'd suggest at least documenting that the screen will still go off, and suggesting what can be done to prevent that...
I'm trying to get info for a sound located at:
https://api.twilio.com/2010-04-01/Accounts/AC59f045f6bbe657c72a2bfbdf7736b5cd/Recordings/RE8d57ef4c537183172c3c819fcbff6b66.mp3
for some reason I received the following error:
RCTJSONStringify() encountered the following error: Invalid number value (NaN) in JSON write
Thanks for the good library. It is playing background well, But, It is not showing controls in background/lock screen mode in notification bar.
Is there anything do we need to enable, But, I did not found anything regarding this in documentation.
Please check following link for more details about this query.
)Can anyone help us?
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
export function playSoundEffect (soundUrl, isSystemMusic) { const callback = () => { AudioPlayer.play() } if (isSystemMusic) { AudioPlayer.prepareWithFile(soundUrl, 'mp3', callback) } }
Expected behavior
It can play in IOS and Android but
It only cann't play in Android 6.0 RIO-AL00 and get Error like This
attempt to invoke virtual method 'void android.media.Mediaplayer.setOnCompletionListener (android.media.MediaPlayer$OnCompletionListener)'
on a null object reference
- playUrl
RNSoundPlayerModule.java: 56
- inkove
Method.java
Platform (please complete the following information):
Additional context
Add any other context about the problem here.
My codes :
import SoundPlayer from 'react-native-sound-player';
playTrack(){
try {
SoundPlayer.playSoundFile('free', 'mp3');
} catch (e) {
console.log(cannot play the sound file
, e);
}
}
When I call this function I get error in console log;
"cannot play the sound file TypeError: Cannot read property 'playSoundFile' of undefined"
What I should do ?.. I checked all options again and again, I linked correctly, mp3 files are located in raw.. I dont know what else I can do .
Edit: I run react-native run-android to compile the project again now its not giving error but I dont hear any sounds..
Trying to build in Xcode - getting
library not found for -lPlaySound
error consistently. It does not seem to be present in the repo itself - am I missing anything?
Hello guys I try to follow the instruction above but it seems that it is not working. it showing me this error
undefined is not an object(eveluating 'RNSoundPlayer.playSoundFile')
Im running it on android
using react-native version: "version": "0.44.0"
Xiaomi mi 5s and mi 8 lite doesn't play a stream on android 8 version devices. Waiting 10 minutes then starts playing.
In README file, under addEventListener
section there's an error:
_onFinishedPlayingSubscription = SoundPlayer.addEventListener('**FinishedPlyaing**', ({ success }) => {
Instead of:
_onFinishedPlayingSubscription = SoundPlayer.addEventListener('**FinishedPlaying**', ({ success }) => {
This caused a bug from my quick copy/paste =)
Describe the bug
I'm using react-native-sound-player in my application, I want to play the multiple tracks at a time, but this module only allows me to play a song at a time.
Is there any way to do this using this module.
Expected behavior
Play the multiple songs at a time
Platform (please complete the following information):
Hi,
Thanks for your library, but I have a problem. Android works well, but on iOS (using iOS 12.1 and react-native 0.57.4) it doesn't work. The callback onFinishedPlaying is getting fired even if no sound comes out from the device.
Here's the screen that shows where I've placed the mp3.
It doesn't work even if I load a sound from the web.
Also, it doesn't throw any error.
Thanks again,
Nicholas
I am getting this error for the verifyReleaseResources
Gradle task after upgrading to
AAPT: error: attribute 'package' in tag is not a valid Android package name: 'rnsoundplayer'.
When I run my app I get this error:
Native module cannot be null.
I'm using React 16.0.0-alpha.12 because I'm using Expo.
Thanks for the great library. But, On seek forward is working fine, But, Rewind(back) not playing.
I am using slider for forward and rewind the audio.
SoundPlayer.seek(sliderValue);
SoundPlayer.play();
Any suggestions?
Hi!
A method to stop playing would be nice :)
Thanks!
Derk
Hi @johnsonsu
I am currently working at a project where it is very important to synchronize a particular action with a sound effect. Now I discovered that there sometimes is a slight delay between the playSoundFile
call and when I can actually hear the sound. I believe this might be because the system needs some time to load the sound first..?
However, a great solution for this would be to have a callback similar to onFinishedPlaying
that is called as soon as the sound is loaded and actually started playing. Would it be possible to introduce a new onStartedPlaying
callback for this purpose?
Cheers
It seems the index.js in the package has not registered the FinishedLoading for iOS. I got this warning Sending "FinishedLoading" with no listeners registered.
Hi,
I have a file downloaded this mp3: https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3 using react-native-fs
into MAIN_BUNDLE
on an IOS emulator. I can verify the file is there and I can play it with any audio player on my Mac /Library/Developer/CoreSimulator/Devices/594B5EDF-5E73-4040-9236-2DA23A1BAC86/data/Containers/Data/Application/A60A1E1B-EBD9-4A59-9B90-4A3148D68D7D/Documents/mpthreetest.mp3
Yet, I get this error when I run:
SoundPlayer.playSoundFile(filename, 'mp3');
Looking at RNSoundPlayer.m
I can see that the default location is mainBundle
. I tried with many files mp4, ogg but the same is happening.
When I play the URL directly with
SoundPlayer.playUrl(url)
it plays without a problem, but I need to download files first before playing it to make sure the file is available offline.
Any help would be appreciated!
Error generating signed apk.
React Native version 0.59.8
Steps to reproduce.
yarn add react-native-sound-player
react-native link react-native-sound-player
cd android && ./gradlew assembleRelease
Build fails and shows this message
React Native -v : 0.57.8
How I can setVolume for soundPlayer while I playing an Song. example: "soundPlayer.setVolume(0.5)"
Is there a way to play songs from somewhere other than the main bundle location (eg. external storage or a documents folder) ?
It's a similar question to #10 - but wondering if there is an Android implementation for the fallback mentioned in the solution?
PS. Thank you to you and all contributors for this library, very handy!
If I use playUrl
then I set SoundPlayer.pause(), so in this time for pausing, SoundPlayer is still continue downloading from my Url, is it?
Hello,
Any plan to implement getCurrentTime() and getSongDuration() methods?
Cheers
So in my app I use musics like a radio and, sometimes there is effects like 2-3 seconds. But when radio is open and when I try to play sound effect, its not overlapping?.. instead its closing first music .. what I can do about it?
Thanks for the good library. We are using this, But, For the progress of the audio, We are showing Slider in UI. But, We have to keep move the progress bar status according to audio play.
Is there any method to get keep information about audio status?
And how to track buffering audio state? Is there any delegate method?
Also it is taking time to play URL like 5 to 10 seconds for online streaming, How to get is preparing play kind states?
Hey! Thanks for developing this module, will be using it in an upcoming project.
This is probably a silly error but I've tried following the installation steps but I'm stuck at importing this package.
I opened it on Android Studio to check if it had been imported correctly, and that seems to be an issue.
It's red at the import statement, and I don't see the corresponding folder on the left side section in the project structure.
I followed the steps of installing using NPM & running react-native link.
Hey, first of all great library it's the only one which works without any problems for us!
I've got a question, why is it not possible to add as many event listeners as I'd like? You're deliberately killing off old listeners here:
react-native-sound-player/index.js
Lines 27 to 30 in b9beda5
I am using the sound player all over my app (mostly with playUrl
though) and would love to have more fine grained control than a 'singleton callback'.
In my opinion it would be great to have something similar as the DOM event listener system. What do you think?
Roughly like this:
SoundPlayer.playUrl('https://example.com/some.mp3')
SoundPlayer.addEventListener('URLFinishedLoading', url => {})
SoundPlayer.addEventListener('FileFinishedLoading', (name, type) => {})
I am not sure if this is covering all cases but I think it would be a great improvement.
Hi, I am using this library for playing sound track SoundPlayer.playSoundFile() in my app.
Once a sound track is played, the music running by other apps would be stopped.
Is there any configuration to prevent it?
Thank you for help!
Describe the bug
After upgrading to RN 0.60 an invariant error is called on NativeEventEmitter -> "Native module cannot be null".
To Reproduce
Steps to reproduce the behavior:
Platform (please complete the following information):
Additional context
"react-native-sound-player": "0.10.0"
How can I link this package to iOS manually or using cocopod?
When I call playUrl(url)
, the sound never starts playing. Originally I thought my iOS simulator was just not working correctly, but I added the SoundPlayer.onFinishedPlaying()
event listener to my componentWillMount()
method, and the code inside was never run.
The catch()
function isn't called either so there is no error.
@omkarsk98, you can use the playSound('/pathToTheFileYouWantToPlay/filename', 'filetype')
function with the path to the file and its type. You need to get the path using react-native-fs
or whatever you used to download the file.
I will lock this conversation, please create an issue if you have further questions.
Originally posted by @johnsonsu in #37 (comment)
It returns playSound is not a function when using the above method. It does not show this function even in the module. Is there any alternative? Please help.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.