Skip to content

Resume after pause #609

Description

@IsmaelMiber

I have issue with resume sound after pausing it.

I want to make play pause resume sound.

🪲 The code:

//SoundManager util that i made.

import Sound from "react-native-sound";

const sounds = {
  "crow_sound": {
    sound: "people-talking-2.mp3",
    path: "https://www.pacdv.com/sounds/people_sound_effects"
  },
  "sally_sound": {
    sound: require("./../../assets/sounds/sallysound.mp3")
  },
};
class SoundManager {

  playUserReview(name) {
    try {
      var sound = sounds[name].sound;
      var path = sounds[name].path;
      if (path) {
        this.userReview = new Sound(sound, path, error => {
          if (error) {
            return;
          }
          
          this.userReview.play(success => {
            if (!success) {
              this.userReview.reset();
            }
          });
        });
      } else {
        this.userReview = new Sound(sound, error => {
          if (error) {
            return;
          }
         
          this.userReview.play(success => {
            if (!success) {
              this.userReview.reset();
            }
          });
        });
      }
    } catch (error) {
      console.log(error);
    }
  }

  pauseUsersReviews() {
    try {
          this.userReview.pause(success => {
            if (!success) {
              this.userReview.reset();
            }
          });
    } catch (error) {
      console.log(error);
    }
  }

  resumeUserReview() {
    this.userReview.play((success) => {
      success ? console.warn("success") : console.warn("NotSuccess")
    });
  }
}

module.exports = new SoundManager();

-----------------------

//and this is the function that i used onpress play/pause button.
 
userNameForPlayingRelatedSound = (username) => {
        if(this.state.soundStatus == "notPlayed") {
            SoundManager.playUserReview(username);
            this.setState({soundStatus: "played"});
            console.warn("played");
        }
        else if(this.state.soundStatus == "played") {
            SoundManager.pauseUsersReviews();
            this.setState({soundStatus: "paused"})
            console.warn("paused");
        }
        else if(this.state.soundStatus == "paused") {
            SoundManager.resumeUserReview();
            this.setState({soundStatus: "played"})
            console.warn("resume");
        }
        
    }

💡 Possible solution

Is your issue with...

  • iOS
  • Android
  • Windows

Are you using...

  • React Native CLI (e.g. react-native run-android)
  • Expo
  • Other: (please specify)

Which versions are you using?

  • React Native Sound: last version
  • React Native: ^0.59.10
  • iOS:
  • Android: 9

Does the problem occur on...

  • Simulator
  • Device

If your problem is happening on a device, which device?

  • Device: Pocophone F1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions