I've been trying to get the Media element to work in PhoneGap when deploying to Android. Here's what I did so far:
Download and install the below:
Java (Version 7 Update 25)
http://java.com/en/download/index.jsp
Java SE Development Kit 7u25 (64 bit)
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Ant (1.9.2)
http://www.apache.org/dist/ant/binaries/
NodeJS (v0.10.18 64 bit)
http://nodejs.org/
Android SDK (ADT Bundle for Windows) 64 bit - version 2013-07-29
http://developer.android.com/sdk/index.html
Installation folder: E:\PhoneDev\adt-bundle-windows-x86_64-20130729
Set environment variables:
JAVA_HOME = C:\Progra~1\Java\jre7
ANT_HOME = E:\Program Files (x86)\apache-ant-1.9.2
NODEJS = E:\Program Files (x86)\nodejs
Verify that the following paths are added to the PATH Environment variable (separated by semi-colons):
E:\PhoneDev\adt-bundle-windows-x86_64-20130729\sdk\platform-tools
E:\PhoneDev\adt-bundle-windows-x86_64-20130729\sdk\tools
%ANT_HOME%\bin
%NODEJS%
E:\Program Files\Java\jdk1.7.0_25\bin
Install PhoneGap (Right now it's version 3.0.0):
npm install -g phonegap
Create phonegap app:
phonegap create media-app
Build phonegap app:
cd media-app
phonegap local build android
Add in media-app\platforms\android\res\xml\config.xml:
<feature name="Media">
<param name="android-package" value="org.apache.cordova.AudioHandler" />
</feature>
Add in platforms\android\AndroidManifest.xml:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Replace the contents of media-app\www\index.html with the "Full Example" on the following page:
http://docs.phonegap.com/en/3.0.0/cordova_media_media.md.html#Media
Run phonegap app in emulator:
media-app\platforms\android\cordova\run.bat
The application runs correctly, but when I try to play a sound I get the following error:
Uncaught ReferenceError: Media is not defined at
file:///android_asset/www/index.html
I also tried doing the same thing from Eclipse which is bundled with the Android SDK. I created an AVD and ran the application from Eclipse. I get the same error. I’ve been trying to understand what the problem is for a while. If someone can shed some light on this problem I would really appreciate it!
As of version 3.0, PhoneGap implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-line Interface, to add or remove this feature for a project:
You need to add the media plugin to your project -
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
Run that above command within the project's directory and you should be set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With