Closed antoine-pous closed 3 years ago
Hey @antoine-pous! Happy that someone takes care here. Are you one of the new maintainers? Can you already tell a rough time estimation when this can be merged? Thanks for your effort.
@pawelsas I'm not a maintainer, actually I need some help to test everything and see how to implement CI.
I'm new to React Native then many things remain a bit hard to understand.
Feel free to use it following instructions and report any issue directly on this PR, I'll check about them ASAP :)
@antoine-pous really cool! I haven't looked in the implementation details yet. Are you planning to update the preloading and memory handling on Android as well? After some research I noticed that audio preloading and/or playback will fail at some point when you either preload to many sounds or play too many sounds within one session.
I never reached it, then i don't know how to deal with it :')
Thank you Antoine for your amazing work. It looks like a very good start for keeping react-native-sound. @pawelsas do you have any demonstration of memory failure when loading too many sounds?
@RomualdPercereau I've not updated this PR since a while, but I think it will be more easy to fix any issue now. My project moved from RN to UE4, but don't hesitate to ping me if you need some help for fixes :+1:
I hope this PR will ensure the future of this package :)
Thank you @antoine-pous, your work is a very good start for the next versions. I moved it in a new branch : https://github.com/zmxv/react-native-sound/tree/1.0.0.
I was wondering why, the functions not related to a specific sound like: enableInSilenceMode
, setMode
were in the Sound class? So I moved them outside the class to be able to use them globally, also changed Sound
to default export. (https://github.com/zmxv/react-native-sound/commit/199f2dade65bab60e6e56608334739fd229eddb9)
It should probably be the same for setSpeakerphoneOn
and setSpeakerphoneOff
do you have a clue to avoid these functions to be related to a sound?
The new usage would be:
import Sound, { enableInSilenceMode } from "react-native-sound"
const sound: Sound = new Sound("test.mp3", "MAIN_BUNDLE")
sound.isLoaded().then(() => {
sound.play()
})
enableInSilenceMode()
Maybe would it be better to wrap those functions in Sound class and move tracks in a Track class, then into the Sound class you maintain a map of the whole loaded sounds and everything can be managed from the Sound class :)
Yes, could be a way to have a dedicated namespace for these functions. It could give this kind of implementation. I don't know if Sound should be default in that case? @antoine-pous
import Sound, { Track } from "react-native-sound"
const track: Track = new Track("test.mp3", "MAIN_BUNDLE")
track.isLoaded().then(() => {
track.play()
})
Sound.enableInSilenceMode()
This is a work in progress, it need some fixes and requires a lot of tests.
What's new:
rejectOnUnsupportedFeature {Boolean}
which ensure that using an unsupported feature will be rejected. If disabled (default behavior) the function will be resolvedenable
/disable
setSpeakerphoneOn
/setSpeakerphoneOff
enableInSilenceMode
/disableInSilenceMode
setActive
/setInactive
SoundBasePath
type which can be'MAIN_BUNDLE' | 'DOCUMENT' | 'LIBRARY' | 'CACHES' | string
SoundOptions
interface withrejectOnUnsupportedFeature?: boolean
andenableSMTCIntegration?: boolean
RNSoundModule.createMediaPlayer
will execute the callback error with more explicit messages.Resource not found
covered too much errors, this update will give a better view of what's happening exactly.Resource not found
remain as last error when the function is not able to determine which action is requested, maybe should we put a better error message. Error payload have also a new key namedresource
which provide the full path of the fetched file to enhance debugging.Known issues
IsAndroid
istrue
predefined directories areundefined
using React Native with ExpoRemaining changes:
This is clearly a braking change and i don't see any reason to continue to support legacy stuff when most of supported versions of RN, by this lib, are not supported anymore. If people are not able to upgrade their dependencies and follow the new standards it's sad but IMO a library must remain updated, they can still use legacy versions of the library if needed.
Feel free to suggest any changes, i need this update then i'll finish it ASAP
To test it in your projects:
Using Yarn:
yarn add antoine-pous/react-native-sound#1.0.0
Using NPM:npm install git://github.com/antoine-pous/react-native-sound.git#1.0.0 --save
Usage example