zmxv / react-native-sound

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

两个不同的实例之间会互相干扰 #616

Closed liaokaime closed 3 years ago

liaokaime commented 4 years ago

当我使用如下代码,5秒钟后,a的播放会停止,a与b属于两个不同的实例,但它们之间却会互相干扰,如何使得它们互相不干扰?

        let a = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            a.play();
        });

        let b = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            setTimeout(()=>{b.pause()},5000);
        });
liaokaime commented 4 years ago

当我使用如下代码,5秒钟后,a的播放会停止,a与b属于两个不同的实例,但它们之间却会互相干扰,如何使得它们互相不干扰?

        let a = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            a.play();
        });

        let b = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            setTimeout(()=>{b.pause()},5000);
        });

我的试过另一种写法,它们不会互相干扰,为什么?

let a = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            a.play();
            let b = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
                setTimeout(()=>{b.play()},5000);
            });
        });
liaokaime commented 4 years ago

Anybody know why?

liaokaime commented 4 years ago

如果您需要帮助,请用英文写

When I use the following code, after 5 seconds, the play of a will stop, a and b belong to two different instances, but they will interfere with each other, how to make them do not interfere with each other?

        let a = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            a.play();
        });

        let b = new Sound(this.url,Sound.MAIN_BUNDLE,(e)=>{
            setTimeout(()=>{b.pause()},5000);
        });

Thank you for your reminding. I used English to describe the problem.