开发者

problem to play sound from URL [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

i want to play a sound from url :: but i cant able to do that , i have implement this code

package com.TestAudio;


import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;

public class TestAudio extends Activity {
    /** Called when the activity is first created. */
    private MediaPlayer xmPlayer2, xmPlayer3, xmPlayer4, xmPlayer5, xmPlayer6,
    xmPlayer7,xmPlayer8,xmPlayer9,xmPlayer10,xmPlayer11;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);




        prepareforaudio(xmPlayer2,"bike_route.mp3");
        prepareforaudio(xmPlayer3,"closed.mp3");
        prepareforaudio(xmPlayer4,"exit.mp3");
        prepareforaudio(xmPlayer5,"no_parking.mp3");
        prepareforaudio(xmPlayer6,"one_way.mp3");
        prepareforaudio(xmPlayer7,"phone.mp3");
        prepareforaudio(xmPlayer8,"rail_road_crossing.mp3");
        prepareforaudio(xmPlayer9,"sale.mp3");
        prepareforaudio(xmPlayer10,"stop.mp3");
        prepareforaudio(xmPlayer11,"turn_off_tap.mp3");



    }
    public void prepareforaudio(MediaPlayer player,String music1)
    {
        try
        {
        player.开发者_C百科setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.setDataSource("http://xyz/MRESC/images/test/"+music1);
        player.prepare(); 
        player.start();
        }catch (Exception e) {
            // TODO: handle exception
        }
    }
}

Permission :

 <uses-permission android:name="android.permission.INTERNET"></uses-permission>


initialize your media player object as MediaPlayer mplayer=new MediaPlayer();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜