I have code to play the .ogg audio file that I downloaded from the Internet. I have no errors, so I can start it, but then the application crashes:
package play.my.sound; import android.app.Activity; import android.media.AudioManager; import android.media.SoundPool; import android.media.SoundPool.OnLoadCompleteListener; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; public class PlaySound2Activity extends Activity { private SoundPool soundPool; private int soundID; boolean loaded = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View view = findViewById(R.id.textView1); view.setOnClickListener((OnClickListener) this);
I think I have two problems:
I put this in the main.xml file:
<? xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: orientation = "vertical" android: layout_width = "fill_parent"
android: layout_height = "fill_parent">
<TextView android: text = "Click on the screen to start playing"
android: id = "@ + id / textView1" android: layout_width = "fill_parent"
android: layout_height = "fill_parent"> </TextView>
</LinearLayout>
And I do not know if this is correct.I put the sound1.ogg file in the workspace->SoundPlay2 , because I had problems in the res folder, and I also tried to put it in two existing res folders.
This is from my console:
[2012-01-04 19:38:16 - PlaySound2] Failed to install PlaySound2.apk on device 'emulator-5554': timeout [2012-01-04 19:38:16 - PlaySound2] Launch canceled! [2012-01-04 19:47:33 - PlaySound2] Error in an XML file: aborting build. [2012-01-04 19:52:34 - PlaySound2] res\layout\main.xml:0: error: Resource entry main is already defined. [2012-01-04 19:52:34 - PlaySound2] res\layout\main.out.xml:0: Originally defined here. [2012-01-04 19:52:34 - PlaySound2] C:\Users\Natalia\workspace\PlaySound2\res\layout\main.out.xml:1: error: Error parsing XML: no element found
I took this example from Android Sounds - Tutorial . "I want to play an audio file, in particular a .wav file.
I do not know where I can find information about the files that are allowed in the MediaPlayer class and their characteristics (durantion, sample rate ...) Could you tell me where I can find this?
source share