Note that there are some explanatory texts on larger screens.

plurals
  1. POcan the android emulator play audio
    primarykey
    data
    text
    <p>I wanted to record and pass through the recorded sound to the phone's speaker, but I could not get the recording code to work (app crashes, <a href="https://stackoverflow.com/questions/18125780/using-microphone-in-android-emulator-java-android-beginner">SEE MY ATTEMPT HERE</a>) so I am now trying to see if the emulator can do anything related to audio or not. I copied a 1 sec recording, in both wav (16 bit pcm, 44k sampling frequency, mono) and mp3 (recording and conversion both done through Audacity) to the sdcard. I can see the files in the IDE's file explorer, so I guess the sdcard is being properly detected by the emulator. But I could not get the emulator's built in music player to detect them (Why ??). </p> <p>As a second attempt, I copied the code <a href="http://mobilecomputing650003.wordpress.com/2011/09/17/how-to-play-mp3-file-in-a-android-emulator/" rel="nofollow noreferrer">HERE</a> to the sample hello world Android app. Here's the main activity class </p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // String PATH_TO_FILE = "/sdcard/asMP3.mp3"; // String PATH_TO_FILE = Environment.getExternalStorageDirectory().getPath()+"/asMP3.mp3"; String PATH_TO_FILE = Environment.getExternalStorageDirectory().getPath()+"/wavSigned16bitPCM.wav"; MediaPlayer mp1 = new MediaPlayer(); try { mp1.setDataSource(PATH_TO_FILE); mp1.prepare(); mp1.start(); Toast.makeText(getApplicationContext(), "HERE", Toast.LENGTH_SHORT).show(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>I assumed this would start playing the sound as soon as the app starts. The <code>Toast</code> shows up so I know the code is executing. The program does not crash but nothing else happens either, no sound in this case as well (Why ?) </p> <p>As a third attempt, I used the code <a href="http://android-er.blogspot.kr/2010/07/android-mediaplayer.html" rel="nofollow noreferrer">HERE</a>, and added the files I wanted to play in <code>res\raw</code> as it says. This program does not crash either, but I still cannot hear anything. </p> <p>So the question is, is it possible to do anything at all related to audio, on the emulator? Looking at <a href="https://stackoverflow.com/questions/9307384/sound-plays-in-emulator-but-not-on-device">THIS QUESTION</a> it looks like this should be possible, so why isn't it happening in my program? Do I need to set any permissions int he manifest for audio output as well? </p> <p>----EDIT---- </p> <p>I have also seen <a href="http://www.anddev.org/video-tut_-_playing_mediamp3_on_the_emulator-t156.html" rel="nofollow noreferrer">THIS</a>, but if I use the <code>-useaudio</code> option the emulator just says <code>-useaudio</code> is an unknown option, and <code>emulator -help</code> does not list it, hen it is clearly shown as an option in the developers website and moreover it says that useaudio is enabled by default. So why isn't my emulator playing any sound? </p> <p><strong>--- UPDATE ---</strong><br> It seems the audio features do not work if the emulator has been started using a snapshot. If not, the audio feature still may or may not work depending on the computer. Please see <a href="https://stackoverflow.com/questions/18179035/android-emulator-not-playing-any-sound-at-all-including-the-built-in-text-to-sp">HERE</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload