danielsogl / awesome-cordova-plugins

Native features for mobile apps built with Cordova/PhoneGap and open web technologies. Complete with TypeScript support.
https://danielsogl.gitbook.io/awesome-cordova-plugins/
Other
2.41k stars 2.42k forks source link

MediaPlugin.create promise never fires #1405

Closed aifer2007 closed 7 years ago

aifer2007 commented 7 years ago
import { MediaPlugin, MediaObject } from '@ionic-native/media'; // for voice
import { File } from '@ionic-native/file'; // for voice

constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private media: MediaPlugin,
              private file: File) {
  }    

let voiceFilePath = this.file.documentsDirectory;
let voiceFileName = 'voiceFile.wav';
let voiceFileFullPath = voiceFilePath + voiceFileName;

this.media.create(voiceFileFullPath)
      .then((voiceFile: MediaObject) => {
        alert("start recording");
        voiceFile.startRecord();
});

alert("start recording") in callback never be fired, also the voiceFile.startRecord();

aifer2007 commented 7 years ago

https://github.com/driftyco/ionic-native/pull/1220

I have saw the issue, the fix doesn't work?

Abdullah-FAl commented 7 years ago

The same problem I've been trying since 5 days But so far I have not found a convincing solution

If you solve it please tell me

Abdullah-FAl commented 7 years ago

this is my code

import { Injectable } from '@angular/core'; import { Platform} from 'ionic-angular'; import { MediaPlugin, MediaObject } from '@ionic-native/media';

/* Generated class for the RecordingAudio provider.

See https://angular.io/docs/ts/latest/guide/dependency-injection.html for more info on providers and Angular 2 DI. */

@Injectable()

export class AudioRecorder {

public filename1: string = "" ; public file:any ; public position:any ; public status:any = 0;

constructor( private media: MediaPlugin, public platform: Platform,

) {

if (this.platform.is('ios')){ this.filename1 = "../Documents/NoCloud/audio.wav"; ///this.filename1 = "../Documents/NoCloud/audio.wav"; }else if (this.platform.is('android')){ this.filename1 = "///storage/emulated/0/Android/data/appId/files/audio.wav"; ///storage/emulated/0/Android/data/data/appId/files/ } else{ console.log("opsss") }

}

startRecording(){

// Create a MediaPlugin instance. Expects path to file or url as argument // We can optionally pass a second argument to track the status of the media

// Recording to a file this.media.create(this.filename1)

.then((file: MediaObject) => { this.file = file console.log("opsss")

});

this.file.startRecord();

}

stopRecording() {

this.file.stopRecord();

}

startPlayback() {

this.file.play();

}

}

Abdullah-FAl commented 7 years ago

screen shot 2017-04-23 at 10 31 04 am And this is the ERROR i get from safari console log in mac os

baksagimm commented 7 years ago

You're right. Updating to 3.5.0 the promise problem emerges. Try version 3.4.4 for now. (But 3.4.4 has problems too. it don't seem to retrieve audio position and duration of the file no matter how long i wait.)

saniyusuf commented 7 years ago

This is a major problem as it seems updating to the latest version removes the promise since now a Media object is returned so all legacy apps will break. ANy status on this. I dont mind submitting a PR to fix this as it makes it a breaking change

ihadeed commented 7 years ago

@saniyusuf

The last version fixed the implementation by not returning back a promise. If you look at the plugin's source code here you can see that the success callback is not used when creating a new instance. Therefore, we shouldn't wait for the promise to resolve to return back the media object.

I thought this plugin worked fine after 3.6.1 .. but if there are still issues then I'll do some testing soon in my playground app.

danielehrhardt commented 7 years ago

https://github.com/driftyco/ionic-native/issues/1452

ihadeed commented 7 years ago

Just pushed an update to Media plugin that will be available in the next Ionic Native release.

this.media.create(...) will always return an instance of MediaObject now. This instance will only function if the plugin actually exists. This way it will not break your code in the browser ... etc.

If you want to only run your code when the plugin is available, wrap it with if(MediaPlugin.installed()).

I reviewed the implementation of the plugin and it seems like everything is implemented correctly, so if there are any issues I highly doubt that they are Ionic Native related. It is most likely issues with Apache's plugin.