Android app not playing mp3 (locally stored mp3s) - android

I have a phonegap app and I'm trying to play mp3's which are stores in the app's folder like this:
--App Root
-- audio
-- mp3s
--Mp3's are all here
Now, the problem is only with Android because it works fine in IOS. On android I'm getting the audio player but no sound is coming out.
Here is the code:
//JS
var
audiofile = 'audio/mp3s/'+result.text+'en.mp3';
//HTML
<audio class="audioPlayer" controls>
<source src="'+audiofile+'" type="audio/mpeg">
</audio>
How can I fix this?

On android you may need to prefix the path to the file with "/android_asset"
So use "/android_asset/audio/mp3s/" as the base directory.

Try to debug the app with chrome Inspect Devices (DevTools little menu), and see if there are any errors.

Related

Cordova Android local video playback used to work; now doesn't

I have a Cordova application which downloads a video file to local storage and then plays it using a HTML <video> tag. This worked fine on iOS and Android up on Cordova version 3.7.1. I recently updated Cordova to the latest version (6.3.1) and now the video doesn't play on Android. iOS is working fine.
The video file is saved to file:///storage/emulated/0/Android/data/org.my.package/foobar.mp4; using ADB, I can see the file is being correctly saved (using FileTransfer) to that location. File size is correct, and permissions are user and group readable.
The video doesn't seem to load at all; v.src is empty, and v.duration is NaN, and v.networkState is 3 (NETWORK_NO_SOURCE)
The video element is
<video id="video" playsinline="1" webkit-plays-inline="1" poster preload="metadata">
<source id="source" type="video/mp4"
src="file:///storage/emulated/0/Android/data/org.my.package/foobar.mp4">
</video>
I haven't changed the HTML or the Javascript since upgrading Cordova to 6.3.1.
(Previous wrong answer removed.)
I think the problem was actually the Crosswalk plugin. Adding or removing the plugin doesn't take effect until you remove the platform and add it again, so I didn't suspect that.
Specifically, I had turned on the Crosswork option --enable-unified-media-pipeline to try to help me with a different issue (ability to set the video playback speed). Removing that option makes it work again. This is counter-intuitive because you're often recommended to turn that option on to fix video issues.

cordova android - how to play videofile that is located inside the project itself

I'm trying to play video that is packaged within the project but it does not work. However videos from the web work just fine.
This problem is android specific, works fine on iOS.
I've been searching, but mostly people have problems with older versions, where they can't play any of the video's, hence I made a new question which is not duplicate because, again, videos are working fine, only those who are packaged with the project itself does not.
Working example
<video autoplay controls width="1024" height="714" class="videoWrapper">
<source src="http://web.com/vid.mp4"></source>
</video>
Not working example
<video autoplay controls width="1024" height="714" class="videoWrapper">
<source src="vid.mp4"></source> <!-- also tried /vid.mp4 -->
</video>
Is the video file there? Yes it is, I can see it in build asset www as well as project size is appropriate, which makes me think that there is sure a video inside the *.apk file.
Whenever you want to access files inside the application, like the www folder, you have to first obtain the file system path and then append your file location and name. See here for how to achieve it.
Phonegap - How to access file in www-folder?

html5 audio on apache cordova android native app

Do audio tag works on an android native app?
I've been searching a while now, but I can't find a post that tells me if it is supported or not, or what do I have to do to make it work.
<audio id="Multimedia1" controls="controls" width="100%" height="30px">
<source src="file:///android_asset/www/Resources/audio.mp3">
Your browser does not support audio.
</audio>
It doesn't load the audio.
I've tried different paths, such as:
Resources/audio.mp3
www/Resources/audio.mp3
file:///android_asset/www/Resources/audio.mp3
If I browse the index.html with the browser (no native app), the audio plays fine with a relative path.
But I just can't make it work it with an apache cordova app.
Any ideas?
Thanks in advance!
I had the same issue with audio tags from HTML5 in Cordova 2.3.0. What I ended up doing was to just play them using JavaScript:
Here's the audio.js I put in the js folder:
function playAudio(src) {
src = '/android_asset/www/' + src;
var media = new Media(src, success, errorThrown);
media.play();
}
function success() {}
function errorThrown(e) {
alert('Error while playing the sound!');
}
And then in your HTML code you do:
<script src="js/audio.js"></script>
And to play the sound add this in a <script> block:
playAudio("media/your_sound.wav");
Same problem: I found the issue is that in order to be able to use the .play() function in HTML5 audio it must run within an user interface event handler (e.g. click) as detailed here:
https://code.google.com/p/chromium/issues/detail?id=178297
This is common policy in mobile browsers to attempt to avoid sites that would autoplay stuff and burn through data it seems. One can use this https://gist.github.com/blairvanderhoof/9380545 to set the webview used by the app to get around this. I am working on making a plugin that when installed will change this behaviour.
-Mike

Can't play audio in Android device

I want to make something like this :
<audio controls>
<source src="media/blablabla.mp3" type="audio/mpeg"></source>
</audio>
I run my app on local host :8080/console and it worked (The music can played). But when I run that apps on my device, the music can't played.
My Device OS is Android 4.1.2
See this question for an answer: IBM Worklight 6.1 - Unable to play a local media file using Cordova
Copy-paste of my answer:
... for playing a local media file, you need to provide the full path
to the media file's location where it'll be in the generated Android
project. For example, if you create a common\audio folder in the
Worklight application and place a .mp3 file in it, you need to use the
following path (in the HTML or JavaScript, or however you'd like...):
Play Audio
Sample project: Android Cordova Media API

HTML audio player not working in Android app

I am working in Android app using html, jQuery, phonegap.
Here I am trying to put HTML5 audio player.That is not working with the local app song path in app folder but when I put an online song path that works fine(ex: http://example.com/audio1.mp3)
In Below my coding with path from online song url which is working:
<audio id="audio-player" src="http://example.com/audio1.mp3" type="audio/mp3" controls="controls"></audio>
In Below my coding with local app path which is not working:
<audio id="audio-player" src="/android_asset/www/media/demo.mp3" type="audio/mp3" controls="controls"></audio>
I was trying to resolve this but no success.
In the second case the src is wrong.
It should be file:///android_asset/www/media/demo.mp3.

Categories

Resources