hi i am developing android application in which i need to play a saved mp3 voice when someone click on button. on clicking button another activity will be opened and saved voice should be played how can i do it??

Regards

有帮助吗?

解决方案

First, you need a service to play MP3 via android.media.MediaPlayer

Second, you can put your saved MP3 in res/raw folder. (manual create it, if it doesn't exist)

And this could help : Get URI of .mp3 file stored in res/raw folder in android

......

cheers~

其他提示

Here is a sample of code:

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        int res = getResources().getIdentifier ( "yourfile", "raw","your.package.here" );
        mPlayer = MediaPlayer.create ( YourActivity.this, res );
        mPlayer.start();
    }
});

You should create a directory res/raw with the file yourfile.mp3 in it

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top