Uncaught ReferenceError: media not defined.

I am trying to get a Media item to work in PhoneGap when deploying to Android. Here is what I have done so far:

Download and install 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 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 

Ensure that the following paths (separated by half-colonies) are added to the PATH environment variable:

 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 (now it is version 3.0.0):

 npm install -g phonegap 

Create a phone saver application:

 phonegap create media-app 

Create an application to connect to the phone book:

 cd media-app phonegap local build android 

Add to media-app \ platform \ android \ res \ xml \ config.xml:

 <feature name="Media"> <param name="android-package" value="org.apache.cordova.AudioHandler" /> </feature> 

Add to 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 β€œFull Example” on the next page:
http://docs.phonegap.com/en/3.0.0/cordova_media_media.md.html#Media

Launch the phonegap application in the emulator:

 media-app\platforms\android\cordova\run.bat 

The application works correctly, but when I try to play the sound, I get the following error:

 Uncaught ReferenceError: Media is not defined at file:///android_asset/www/index.html 

I also tried to do the same with Eclipse, which comes with the Android SDK. I created AVD and ran the application from Eclipse. I get the same error. I tried to understand what the problem was for a while. If anyone can shed light on this issue, I would really appreciate it!

+7
javascript android cordova
source share
1 answer

Starting with version 3.0, PhoneGap implements device-level APIs as plug-ins. Use the CLI plugin command described in the command line interface to add or remove this function for the project:

You need to add a media plugin to your project -

 phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git 

Run this command above in the project directory and you should be installed.

+7
source share

All Articles