zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 748 forks source link

v1.0.0 #713

Closed antoine-pous closed 3 years ago

antoine-pous commented 3 years ago

This is a work in progress, it need some fixes and requires a lot of tests.

What's new:

Known issues

Remaining 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

const sound: Sound = new Sound('sound.mp3', 'MAIN_BUNDLE', {rejectOnUnsupportedFeature: true})
sound.isLoaded().then(() => {
  sound.play()
})
sasweb commented 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.

antoine-pous commented 3 years ago

@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 :)

sasweb commented 3 years ago

@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.

antoine-pous commented 3 years ago

I never reached it, then i don't know how to deal with it :')

RomualdPercereau commented 3 years ago

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?

antoine-pous commented 3 years ago

@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 :)

RomualdPercereau commented 3 years ago

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()
antoine-pous commented 3 years ago

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 :)

RomualdPercereau commented 3 years ago

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()