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
Related
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.
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" ?)
I'm recording/selecting video with media-capture plugin, convert it to mp4 with video-editor plugin and after the user confirms the selection I copy/move this file to app specific media dir (something like /storage/emulated/0/APPNAME/Video/).
Everything works fine, except that if the user tries to open the video file immediately, the native video player will open but there'll be a message like "Could not play video" (on android) and the console.log shows the error "File not found".
This happens on both iOS and Android.
I use this plugin to open video files in native players.
If I exit the app and reopen it, the issue dissapears. So the problem is, I think, that the system does not know about the existance of that new copied/moved file. Is there a way to refresh the filesystem?
I have checkd the file URI that I pass to the openfile plugin and it's the same when it works & when it doesn't.
I use HTML5 FileSystem to copy/move files.
I use promisses, I wait until files are copied/moved, so it's not this the issue.
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.
I have few SWF Files which I want to run view on my Android Device.
Earlier I was viewing those files in webview using flash player but now as flash player plugin is no more available on play store so the person who has not flash player plugin already can not view those files.
How can I show my SWF files without using Flash Player Plugin ?
You can use opensource code like SWFDec, but you have to porting it on android by yourself.
How to porting:
1. download swfdec source code from http://swfdec.freedesktop.org
2. cross-compile swfdec source code for android platform
3. read swfdec source code to find how to blit swfdec surface to android view
Google's Swiffy makes Flash files HTML5 friendly.
Google's cooked up a new tool in its labs that converts SWF files into HTML5 for use on devices that can't run Flash, including those made by Apple.
I use Adobe AIR for swf files to play b'cause its still free, but it does require you to sign up.. Here is setup require to getting started with Adobe AIR.. There is lot of stuff in that link well, you require only app, for viewing .swf file...
Firefox comes with SWF support. I had to play a SWF file in Android. Here's how I did it.
Download the SWF file to store locally in your device. Most likely by default it will be in the root/sdcard/download folder.
Open Firefox browser. Type in the URL file://root/sdcard/download/myFlashFilename.swf
It should show a "Tap to activate plugin" or similar message. Tap it and it should work.
Add this to Bookmark and Add to Home Screen for easy access.