Audio doesn't work in Android


#1

Hi, I’m developing a web app for kids where, when someone press on the “play” button or clicks an image, a sound is heard.

The problem is that while on browser the audio flawlessly, in Android (both emulator and device) I hear nothing.

In my code I used a simple Media plugin, eg:

	 this.media.create('assets/audio/'+this.storia.mainaudio+'.mp3')
		.then((file: MediaObject) => {
			this.audio = file;
			this.audioLoaded = true;
			});

and in my browser this works perfectly.

When I press the “play” button on my emulator, I hear no sound, I get this from Logcat:

MediaFocusControl: AudioFocus requestAudioFocus() from uid/pid 10071/5359 clientId=android.media.AudioManager@deb768dorg.apache.cordova.media.AudioHandler$1@96ea042 req=1 flags=0x0

When I press the Pause button , I read:
AudioPlayer: AudioPlayer Error: pausePlaying() called during invalid state: 0

(I suppose because the audio is not running)

Thanks in advance for any hint.

Antonio


#2

is https://ionicframework.com/docs/native/media/, right?


#3

Yes, it is. I’ve followed that usage and in fact it works on my browser


#4

It looks like I can’t find the right path, I’ve tried a lot of paths but no one gave me the right result. My audio files are stored in assets/audio/, so I tried every possible interpolation:

“assets/audio/”+file
"/assets/audio/"+file
"android_asset/www/assets/audio/"+file
"/android_asset/www./assets/audio"+file
"android_asset/assets/audio/"+file
"/android_asset/assets/audio"+file
(following this article https://www.raymondcamden.com/2014/06/23/Cordova-Media-API-Example/)

Still no result :frowning:


#5

Never used this before, but “/android_asset/www/assets/audio/filename.extension” should work:


#6

Thank you. I’ll give it a try!


#7

Your answer solved my problem, thank you! By the way, I’ve tried your path more than a year ago, but I’ve now realized that - I don’t know why - my Ionic build doesn’t actually build a new apk file and sometimes it loads the previous version of the file (without the latest modifications I’ve done)…


#8

Hi Folks,

What’s the path for iOS9+ assets?