本文介绍了机器人的MediaPlayer无法播放MP3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了最基础的应用程序,我能想到的,试图播放MP3文件,但它不工作。我没有得到任何错误,但是当应用程序启动时,声音不播放。

I have written the most basic application I can think of to try to play an mp3 file, but it is not working. I don't get any errors, but when the application starts up, the sound is not played.

public class soundtest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MediaPlayer mp = new MediaPlayer();
        mp.create(getApplicationContext(), R.raw.norm_iphone_money);
        mp.start();
    }
}

我在想什么?我有norm_iphone_money.mp3里面的RES /原始文件夹中。该文件在Windows Media Player和iTunes播放罚款。

What am I missing? I have "norm_iphone_money.mp3" inside the res/raw folder. The file plays fine in Windows Media Player and iTunes.

我使用的Java SDK和Eclipse的Java的最新版本。该应用程序是针对Android 2.2的,尽管没有健全的运行良好的模拟器。

I'm using the latest versions of Java SDK and Eclipse for Java. The app is targeted for Android 2.2 and runs fine in the emulator despite no sound.

推荐答案

现在的问题是,媒体音量设置为0(不振铃音量)。你可以通过设置:

The problem is that the media volume is set to 0 (not the ringer volume). You can set it by:

AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);

这篇关于机器人的MediaPlayer无法播放MP3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 07:00