I want to stream and play itunes preview urls like http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a. I tried to use AAC Decoder Android Library. By which I can stream and play AAC stream urls like http://http.yourmuze.com:8000/play/paradise/l.aac. But it dnt stream m4a urls(Logcat says java.io.FileNotFoundException: http://a2.mzstatic.com/us/r1000/044/Music/e9/40/ec/mzm.evyxvimp.aac.p.m4a
).
How I can stream the .m4a links?
My Code:
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;
}
}
Updates
itunes preview Urls
.Is possible to play itunes preview urls
in android?
It has nothing to do with media formats etc. Apple simply prevents non-Apple clients to access previews. You can spoof User-Agent header and access to previews.
Read my relevant blog post here: http://ahmetalpbalkan.com/blog/how-to-bypass-itunes-music-previews-protection/ Thats why you get 404 while playing music on Android. this should answer your question.