HTML audio player not working in Android app - android

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.

Related

Loading an mp4 video from an html link on Android

I have a html file on my Samsung android tablet that has a link like this:
Click to play local 0001_a1.mp4
When I click it I wanted it to open the video file that is in the sub directory /video beneath but only the link background changes like the link is being pressed but no video plays. If I remove the video file and press the link I get an error that it can't find the file. So I know that something is trying to happen. I have also tried
Click to play local 0001_a1.mp4
With the same results. Both work fine when on a Windows PC.
How can I load local videos using an html link on Android?
In mobile browsers you must call window.open inside onClick instead of set href attribute:
<a href="#" onclick="window.open('./video/0001_a1.mp4','_blank')">
Click to play local 0001_a1.mp4
</a>

Android app not playing mp3 (locally stored mp3s)

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.

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

Radio Streaming without flash player?

I am developing an android application to stream live radio.Which method can I use for developing such an application .I have just tried adding html code in html file in assets folder and load them in webview .But it doesnt work without flashplayer .I need to stream it without flash player.
I used Radio this link as HTML code .

Playing local audio file in Android webview app

I have a simple Android webview app, built with Phonegap Build. When trying to play a local mp3 file that's included in the APK, nothing happens. However, if I pull an mp3 from the web it works.
e.g.
<audio src="www.example.com/01.mp3" > WORKS JUST FINE
<audio src="01.mp3" > DOES NOT WORK
I'm new to Android development, so I can only guess that the file is somehow inaccessible by Android's media player. Here's a link to the errors/warnings from my log file if that helps shed any light on the problem.
http://pastebin.com/isS542RE
I have it working using Phonegap's Media class. I must have been doing something wrong initially, but I'm not sure what. The proper way to access it through the media object is as Simon stated previously:
myMedia = new Media("/android_asset/www/test.mp3");
You have to put the full path as the media class defaults to the /SDCARD directory on relative paths.
Simon also has a great write up about using the media class:
http://simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html?m=1
As for the HTML5 method and using the AUDIO tag, I'm still not certain why it fails on local files. Phonegap's media class works just fine though and is probably a more reliable solution anyhow. Phonegap FTW!
Have you tried pointing the file to the local file system path using "file:///android_assets/01.mp3" assuming your .mp3 is within the applications assets directory?
We had the same problem, the media files, in order to be played, needs to be in the external storage dir. Try to move your HTML and related files to /mnt/sdcard/.
I filed an official bug report on this:
http://code.google.com/p/android/issues/detail?id=41995&thanks=41995&ts=1356643666

Categories

Resources