How to stop the sound when it plays in another player in parallel in the Cordova media plugin

I have an audio player in my application that was executed using the Ionic framework Cordova Media Plugin .

I want it to be stopped when another application player is playing media.

I want only one audio player to be active at a time, does anyone know how to do this?

+4
source share
2 answers

It works for me, check it out.

 var filedirPath = $ionicPlatform.is('android') ?  '/android_asset/www/app/audio' : 'audio';

var fileName = filedirPath + "/BlossominyourSmile.mp3";
 var media = new Media(self.fileName, function(){
          console.log("Silence played succssfully");
          // self.resetPlay();
        }, function(err){
      });
 media.play({playAudioWhenScreenIsLocked : true, numberOfLoops: 0}); 

Media , media.pause, media.resume, media.stop
,

if(self.media){ self.media.stop(); self.media.release();}
+1

Ionic 2 cordova-plugin-nativeaudio

, constructor, ,

    platform.ready().then(() => {
            this.preloadTracks()
        });

        preloadTracks(list) {
          var path = this.keypadSounds.getAssetsPath();        
          list.forEach((el) => this.nativeAudio.preloadComplex(el, `${path}/${el}.mp3`, 1, 1, 0).then(
            () => {}, 
            (error) => {})
        );
    }

this.nativeAudio.stop(el);

0

Source: https://habr.com/ru/post/1614258/


All Articles