Phonegap / Cordova - the code does not play audio on android (no problem)

I am working on a phonegap / cordova application that plays audio files stored locally.

I am having problems with some code and android where example 1 is not playing on android and example 2 is playing.

NOTE. Problems are not the way, I know that the path to the file is correct.

Example 1 - Does not work on Android, but works fine on iOS, where the path is changed for iOS.

var audiofile = cordova.file.dataDirectory+'android_asset/www/audio/1.aac'; ... $( ".player" ).html('<div class="audioDemo-wrapper"><audio class="audioDemo" controls><source src="'+audiofile+'" type="audio/mpeg"></audio><div class="closeAudioBtn" onclick="stopAndCloseAudio();">X</div></div>'); $(".audioDemo").trigger('play'); 

Example 2. This works on Android, but it is not as we would like.

 var audiofile = cordova.file.dataDirectory+'android_asset/www/audio/1.aac'; window.open(audiofile, '_blank', 'location=no,closebuttoncaption=Close'); 

The main difference is that a new example opens in a new window? 2.

Why example 1 does not play on Android when it works fine on iOS (Note: paths are not a problem)

Any ideas?

+5
source share
1 answer

With Cordova webview on Android, you can use:

1) Audio HTML5 API (also wrapped in jQuery) for playing audio files from the Internet .

2) Cordova plugins that provide APIs for playing local audio files bundled with the Cordova project; for example, two Cordova plugins for playing audio files:

An alternative is to use Crosswalk in the Cordova project, therefore replacing Cordoba’s own webview with Crosswalk webview. Thus, you have a Chromium-based web view that allows you to support all modern web interfaces, including audio.

Some useful mini-tutorials for the Ionic / Cordova project (applies only to Cordoba projects):

PS: Unfortunately, I could not find in Cordoba documents about web APIs supported by Android Cordova webview

+1
source

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


All Articles