我想流式傳輸並播放像http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a這樣的iTunes預覽URL。我試圖使用AAC Decoder Android庫。通過哪個我可以流並播放AAC流網址,如http://http.yourmuze.com:8000/play/paradise/l.aac。但它是流m4a網址(Logcat說java.io.FileNotFoundException: http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a
)。Android中的Stream和Play .m4a流(Itunes preview Url)
我該如何傳輸.m4a鏈接?
我的代碼:
public class AACPlayerActivity extends Activity implements OnClickListener,PlayerCallback{
private Button btnPlay;
private ProgressBar progress;
private Handler uiHandler;
private MultiPlayer multiPlayer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPlay = (Button)findViewById(R.id.playButton);
progress = (ProgressBar)findViewById(R.id.progress);
progress.setVisibility(View.INVISIBLE);
btnPlay.setOnClickListener(this);
uiHandler = new Handler();
}
public void playerException(Throwable arg0) {
// TODO Auto-generated method stub
}
public void playerMetadata(String arg0, String arg1) {
// TODO Auto-generated method stub
}
public void playerPCMFeedBuffer(boolean arg0, final int audioBufferSizeMs, final int audioBufferCapacityMs) {
// TODO Auto-generated method stub
uiHandler.post(new Runnable() {
public void run() {
// TODO Auto-generated method stub
progress.setProgress(audioBufferSizeMs * progress.getMax()/audioBufferCapacityMs);
}
});
}
public void playerStarted() {
uiHandler.post(new Runnable() {
public void run() {
// TODO Auto-generated method stub
progress.setProgress(0);
progress.setVisibility(View.VISIBLE);
}
});
}
public void playerStopped(int arg0) {
// TODO Auto-generated method stub
uiHandler.post(new Runnable() {
public void run() {
// TODO Auto-generated method stub
progress.setVisibility(View.INVISIBLE);
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(btnPlay.getText().equals("Play")){
start();
btnPlay.setText("stop");
}else{
stop();
}
}
private void start() {
stop();
// we cannot do it in playerStarted() - it is too late:
multiPlayer = new MultiPlayer(this,MultiPlayer.DEFAULT_AUDIO_BUFFER_CAPACITY_MS, MultiPlayer.DEFAULT_DECODE_BUFFER_CAPACITY_MS);
multiPlayer.playAsync("http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a");
}
private void stop() {
if (multiPlayer != null) {
multiPlayer.stop();
multiPlayer = null;
}
}
更新
- 我嘗試使用ServeStream它說的網址無法打開。我試圖用Vitamio SDK它也無法播放
itunes preview Urls
。
是可以在android中玩itunes preview urls
?
什麼是'MultiPlayer'?您是否嘗試將URL傳遞給Android的默認'MediaPlayer'實例? – Devunwired 2012-08-28 17:20:25
我試過,但android默認媒體播放器不能流aac流urls。所以我嘗試使用AAC解碼庫,它使用MultiPlayer而不是MediaPlayer。但它也不是流媒體。 – 2012-08-29 12:51:58
我是ServeStream的開發者。我嘗試了你提供的URL,並且使用最新版本(0.4.11),即FYI玩了沒有問題。 ServeStream將滿足您的要求。 – 2012-09-04 04:35:09