-1
播放聲音,我想從網址:: 播放聲音,但我不能能夠做到這一點,我有實現這個代碼問題從URL
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.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://xyz/MRESC/images/test/"+music1);
player.prepare();
player.start();
}catch (Exception e) {
// TODO: handle exception
}
}
}
權限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
此問題沒有任何背景。如果您可以改進它,請將其標記爲待審查。 –