0
嘿,我無法從我的本地主機服務器(以及其他網站與原始MP3文件)播放流。我的代碼爲已註釋的網站工作,所以我認爲它有一些 做與服務器,而不是Java代碼。android MediaPlayer setDataSource不抓取可播放文件
public class MainActivity extends ActionBarActivity{
\t //static final String ANCHOR = "http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3";
\t static final String ANCHOR = "http://spintron.ddns.net/Random%20Access%20Memories/07%20-%20Touch.mp3";
\t
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MediaPlayer mp = new MediaPlayer();
mp.setVolume(1, 1);
try{
\t mp.setDataSource(ANCHOR);
\t mp.prepareAsync();
}catch(Exception e){
\t e.printStackTrace();
}
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
\t \t \t @Override
\t \t \t public void onPrepared(MediaPlayer mp) {
\t \t \t \t Toast.makeText(MainActivity.this,"Prepared",Toast.LENGTH_LONG).show();
\t \t \t \t mp.start();
\t \t \t \t
\t \t \t }
\t \t });
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
@spinton URL可能是錯誤的或提到這個https://github.com/protocol10/SangeetPlayer/blob/master/src/com/akshay/sangeetplayer/net/StreamInput.java – 2014-10-17 11:57:37