Cordova-plugin-media callback methods

I am using cordova-media-plugin 1.0.1. in the Ionic mobile app. I am using a plugin to play an audio file.

I can make him play using:

var media = $cordovaMedia.newMedia(fileToPlay, // success callback mediaSuccess, // error callback mediaFailure, // status callback mediaStatus ); 

Then I can call media.play () when playing the file.

However, callbacks are never executed. I define them as:

  function mediaSuccess () { console.log("Successfully finished task."); } function mediaFailure (err) { console.log("An error occurred: " + err.code); } function mediaStatus (status) { console.log("A status change occurred: " + status.code); } 

But they are never called. However, this is my console, I see a record from the player himself, when he starts and stops playing:

 Will attempt to use file resource '//var/mobile/Containers/Data/Application/931BFA01-CDA4-43CD-BC16-7FB6A64305DC/Library/NoCloud/DateTime-1446772191539audio_007.wav' Playing audio sample '//var/mobile/Containers/Data/Application/931BFA01-CDA4-43CD-BC16-7FB6A64305DC/Library/NoCloud/DateTime-1446772191539audio_007.wav' Stopped playing audio sample '//var/mobile/Containers/Data/Application/931BFA01-CDA4-43CD-BC16-7FB6A64305DC/Library/NoCloud/DateTime-1446772191539audio_007.wav' 

These registration events go to the console, but they are NOT in my code, so they must come from a media object.

I need to get status changes and / or successful callbacks, since I need to update the model to enable playback, but again when the clip ends.

Any thoughts?

+5
source share
1 answer

After delving deeper into this depth, I found that (despite the documentation) callbacks are not implemented for iOS in version 1.0.1 of the cordova-media-plugin. They are implemented only for Android, FireOS and Windows.

At the bottom of the Media.js file in the www directory, it creates a cordova channel that allows you to subscribe to messages from the main player. Unfortunately, this code only runs for android, fireos and windows phones:

 if (cordova.platformId === 'android' || cordova.platformId === 'amazon-fireos' || cordova.platformId === 'windowsphone') { var channel = require('cordova/channel'); channel.createSticky('onMediaPluginReady'); channel.waitForInitialization('onMediaPluginReady'); channel.onCordovaReady.subscribe(function() { exec(onMessageFromNative, undefined, 'Media', 'messageChannel', []); channel.initializationComplete('onMediaPluginReady'); }); } 

I tried adding ios to the list to see if it was just a gap in this code and it exploded:

ERROR: method 'messageChannel:' not defined in plugin 'Media'

So ... those of us who are building for iOS or other platforms other than Android / Windows are SOL when it comes to callbacks (although the game still works). There seems to be no way to send an Apache error report about this unless this email is sent from the apache.org email address, so I'm not sure if they even know about it.

+3
source

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


All Articles