Cordova media plugin file.play() always plays from start, does not resume


#1

Hello. I’m new to App developement and ionic. I’ve been playing around with creating a simple media player using the cordova media plugin and ionic v2. The effect I would like to achieve is for my local mp3 to play from the start of the track and resume play after a pause using the same button, but when I run the code below, the play button always plays from the beginning of the track. The pause button works fine. Any ideas what I might be doing wrong?

Typescript code:

export class HomePage {
  file;

  constructor(public navCtrl: NavController) {
  }

  mediaplay(){
    this.file = new MediaPlugin('assets/audio/sample1.mp3', (status) => {});
    this.file.play();
  }

  mediapause(){
    this.file.pause();
  }
}

Relevant html code:

<ion-row>
    <ion-col width-20>
        <button ion-button (click)="mediaplay()">
            <ion-icon name='md-play'></ion-icon>
        </button>
    </ion-col>

    <ion-col width-20>
        <button ion-button (click)="mediapause()">
            <ion-icon name='md-pause'></ion-icon>
        </button>
    </ion-col>
</ion-row>

#2

@superbug I had the same issue, it made no sense…I had to store the current position in a variable before pause, and when I pressed play again, seek audio to the stored value. I’ve updated to Ionic 3 and I cannot get this MediaPlugin to work at all anymore, they’ve added a MediaObject Observable which isn’t working for me…

Update: This works in my emulator, not in Ionic view…the .seekTo() doesn’t seem to work on the device. Note: I’m using version 3.4.4 of the Media Plugin to avoid some of the later issues