Cordova官方插件 -- Vibration、Media、NativeAudio

时间:2025-04-02 10:17:55
if( window.plugins && window.plugins.NativeAudio ) { // Preload audio resources window.plugins.NativeAudio.preloadComplex( 'music', 'audio/music.mp3', 1, 1, 0, function(msg){ }, function(msg){ console.log( 'error: ' + msg ); }); window.plugins.NativeAudio.preloadSimple( 'click', 'audio/click.mp3', function(msg){ }, function(msg){ console.log( 'error: ' + msg ); }); // Play window.plugins.NativeAudio.play( 'click' ); window.plugins.NativeAudio.loop( 'music' ); // Stop multichannel clip after 60 seconds window.setTimeout( function(){ window.plugins.NativeAudio.stop( 'music' ); window.plugins.NativeAudio.unload( 'music' ); window.plugins.NativeAudio.unload( 'click' ); }, 1000 * 60 ); }