Can android emulator play audio?

I wanted to record and transfer the recorded sound to the phone speaker, but I could not get the recording code to work (application crash, SEE MY ATTEMPT HERE ), so now I am trying to understand if the emulator can do anything related to audio or not. I copied the recording for 1 second both in wav (16 bit, and on a disc with a sampling frequency of 44 kHz, mono) and mp3 (recording and conversion performed through Audacity) on the SD card. I can see the files in the IDE file explorer, so I think the SD card is properly detected by the emulator. But I could not get the emulator built into the music player to detect them (why?).

As a second attempt, I copied the code HERE to the hello world application for Android. Here is the main activity class

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;
    }
}  

I assumed that this would start playing sound immediately after starting the application. A message will appear Toast, so I know that the code is executing. The program does not crash, but nothing happens and in this case there is no sound (why?)

As a third attempt, I used the code HERE and added the files that I wanted to play in res\raw, as he says. This program also doesn't crash, but I still can't hear anything.

, , - , ? , , , ? - , ?

---- EDIT ----

, -useaudio, , -useaudio , emulator -help , - , , , , useaudio . ?

--- ---
, , . , . .

+4
1

, , , .

-

mp1 = new MediaPlayer();
mp1.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp1.setDataSource(PATH_TO_FILE);
mp1.prepare();
mp1.start();

.

,

-

- Android .

, .

+2

All Articles