play html5 audio from android asset folder? - android

Hi I have developed an Android application which load Html5 file, that contains .mp3 files. The html files are stored inside the android asset folder. But when I try to load, the file is not playing. This is my path. webView.loadUrl("file:///android_asset/kids_sample/baba.mp3");

instead of loading audio files in WebView, load in MediaPlayer class.
and if you really want to load audio files in webView, then you have to code audio files in html file and load that html file in WebView.
example
<html>
<body>
<audio controls>
<source src="kids_sample/baba.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
</body>
</html>

Related

Is it possible to play mp4 file, located inside Download folder on Android WebView via Video Tag?

We have Android device. Inside that device, on internal flash is located Download folder and inside that folder resides cat.mp4
Currently we are using following script:
<video width="365" height="200" autoplay loop controls autobuffer>
<source src="file:///sdcard/Download/cat.mp4" type='video/mp4'>
</video>
We have also tried following script:
<video width="365" height="200" src="file:///sdcard/Download/cat.mp4" autoplay loop controls autobuffer>
</video>
Both scripts do not play local video file.
The html file itself, which contains above video tags, comes from certain remote location (not local).
(If we place cat.mp4 on remote location it plays without any problem)
Is this correct approach to play local mp4 files in WebView?
If not, which part of the code is incorrect?
Is this correct approach to play local mp4 files in WebView?
Nope you can't do that in general (webView or not). Security measures (in HTML protocols) do not allow a web-based application to access a user's files from their hard drive (or other storage).
The user must allow access by selecting the file themselves (hence the browse/select file option in some websites). Only options are:
Put HTML and video files online (load everything from web)
Put HTML in SD card's download folder then you can use src="cat.mp4"
A side issue with your approach begs the question, what happens for site visitors without these files on SD card? Or worse a user not even using Android (on a Win PC how can my browser make sense of src="file:///sdcard/Download/cat.mp4" ?)

How to play videos in android from raw folder and htm file

How can I play videos from a raw folder in an .htm file on android?
Neither of these code snippets work for me:
<video id="video" controls>
<source src="android.resource://tutorials.bodybuilding/raw/smit.mp4" type="video/mp4">
</video>
or
<video id="video" controls>
<source src="url('android.resource://tutorials.bodybuilding/raw/smit.mp4')" type="video/mp4">
</video>
According to reading file in assets or raw folder in Android I guess your addresses are wrong. You should consider what
Uri.parse("android.resource://tutorials.bodybuilding/" + R.raw.csgsmit);
returns for every of your videos and place it into html OR at runtime load html into a String and replace every address using such method and then load modified html using Webview.loadData() or Webview.loadDataWithBaseUrl() passing a modified html (a resluting String).

Audio not working in Android webview

I open a website URL in Android WebView inside an application. One of the web pages contains links to Images and Audio files on server. Server in response reads the file requested and writes the content to Response stream and sets appropriate Content-Type. The images is opening perfectly but audio is not playing, it just flashes a window with the URL and just goes away immediately. I am using Java Script window.open() for this purpose.
When I access the website directly in Android browser, its playing the sound by opening native music player application. I am wondering why the same is not working inside WebView.
Do anybody have idea about such kind of problem? If you have further query on the same, I will provide. Please share your experience.
Thanks!
This is a bug inside the webview. you can use video tag replaced to audio tag as an example:
<video width="320" height="240" controls>
<source src="audio.mp3" type="video/mp4">
</video>

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.

How to get high folder uri in html on android web server

I'm developing an app that installs files ( index.html, style.css ... ) to SD-card of phone for web server
The web server needs to get mp3 files to play.
My problem is what I couldn't find where is my mp3 file??
For example..
It works fine If i put mp3 file in same folder of index.html.
<a href="somthing.mp3"
data-format="mp3 ogg">mp3 file</a>
However, I couldn't get the route of mp3 if I put higher folder than the folder of index.html..
I tried
<a href="/sdcard/MUSIC/somthing.mp3"
data-format="mp3 ogg">mp3 file</a>
and
<a href="http://xxx.xxx.xxx.xxx:8080/sdcard/MUSIC/somthing.mp3"
data-format="mp3 ogg">mp3 file</a>
"http://xxx.xxx.xxx.xxx/index.html" is my android web server ...
How can I get my file???

Categories

Resources