cordova-plugin-media callback methods

前端 未结 1 1648
南旧
南旧 2021-01-13 01:29

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

I am able to get it to play using:

相关标签:
1条回答
  • 2021-01-13 02:30

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

    At the bottom of the Media.js file in the module's www directory, it creates a cordova channel which lets it subscribe to messages from the native player. Unfortunately, that code is only executed for android, fireos, and windows phone:

    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 miss in that code and it blew up:

    ERROR: Method 'messageChannel:' not defined in Plugin 'Media'

    So... those of us building for iOS or other non-Android/Windows platforms are SOL when it comes to callbacks (though playing still works). There seems to be no way to submit a bug report to Apache about this unless it is an email coming from an apache.org email address, so I am not sure they even know about it.

    0 讨论(0)
提交回复
热议问题