0

I'm trying to use ionic native's media plugin like this:

record(){
    ...
    return this.media.create(src,onStatusUpdate).then((mediaObj) => {
        mediaObj.startRecord();
        return mediaObj;
    });
}

And I use the mediaObj returned from it elsewhere, but I also need to know the status of the mediaObj; this apparently comes from passing a second argument, a callback function, to the media.create() function. However, I don't know how to get the mediaObj's status in there. I know the following would work for just telling me the status, but I actually need to access it.

const onStatusUpdate = (status) => console.log(status);

So, the question is, is there a way to simply access the mediaObj's status?

Arfons
  • 96
  • 9

1 Answers1

0

The MediaPlugin status update notification is all you get so set a class property with the value you get when the status change.

To manage the MediaObject I set a property to the value obtained when the promise is resolved.

import { ApplicationRef } from '@angular/core';
...
...

export class PlayerPage {
  track:any;
  file:MediaObject = undefined;
  position:any = undefined;
  status:any = 0;

  constructor(public ref ApplicationRef, public navCtrl: NavController, private navParams: NavParams, public AppstateProvider: Appstate, private media: MediaPlugin) {
    this.track = navParams.get('track');

    media.create('http://.../...mp3',(status)=>{
      this.status = status;
      this.ref.tick();
    }).then((file: MediaObject) => {
      this.file = file;
    });
  }

play() {
  this.file.play();
}

The this.ref.tick(); is necesarry because Angular does not detect this property update - I tried publishing and subscribing Angular still did not detect the property update.