问题
I'm trying to do an app for play video. I've 2 problems:
1) I've a Youtube's link: rtsp:// and i do:
"Uri myUri = Uri.parse(link); //link = rtsp://... mMediaPlayer.setDataSource(getApplicationContext(), myUri);"
Then, the video doesn't play... however, if i use a "videoview" works. I think the problem is that "mediaplayer" doesn't play the mpeg codec. Any ideas?
2) I've several links to a different quality, and i play them connected to wifi and no problem but with data connection:
05-01 15:58:25.453: E/Link:(31565): http%3A%2F%2Fo-o.preferred.mad01s04.v16.lscache3.c.youtube.com%2Fvideoplayback%3Fupn%3D35Zn4tL7Ibc%26sparams%3Dcp%252Cid%252Cip%252Cipbits%252Citag%252Cratebypass%252Csource%252Cupn%252Cexpire%26fexp%3D900147%26itag%3D18%26ip%3D85.0.0.0%26signature%3DAACE528D596873408192BCDDF4ECFC7DDFD68EBB.575689C34D97BA9D750C7B40CC63B427E40E7838%26sver%3D3%26ratebypass%3Dyes%26source%3Dyoutube%26expire%3D1335903378%26key%3Dyt1%26ipbits%3D8%26cp%3DU0hSSllLUV9MUkNOMl9RRVVEOnduVjJoRkFBMDBn%26id%3D8fb5ca7aa1a31f5e
05-01 15:58:25.464: I/AwesomePlayer(31648): setDataSource_l('http://o-o.preferred.mad01s04.v16.lscache3.c.youtube.com/videoplayback?upn=35Zn4tL7Ibc&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=900147&itag=18&ip=85.0.0.0&signature=AACE528D596873408192BCDDF4ECFC7DDFD68EBB.575689C34D97BA9D750C7B40CC63B427E40E7838&sver=3&ratebypass=yes&source=youtube&expire=1335903378&key=yt1&ipbits=8&cp=U0hSSllLUV9MUkNOMl9RRVVEOnduVjJoRkFBMDBn&id=8fb5ca7aa1a31f5e')
05-01 15:58:25.484: V/ChromiumHTTPDataSource(31648): connect on behalf of uid 10101
05-01 15:58:25.484: I/ChromiumHTTPDataSource(31648): connect to http://o-o.preferred.mad01s04.v16.lscache3.c.youtube.com/videoplayback?upn=35Zn4tL7Ibc&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=900147&itag=18&ip=85.0.0.0&signature=AACE528D596873408192BCDDF4ECFC7DDFD68EBB.575689C34D97BA9D750C7B40CC63B427E40E7838&sver=3&ratebypass=yes&source=youtube&expire=1335903378&key=yt1&ipbits=8&cp=U0hSSllLUV9MUkNOMl9RRVVEOnduVjJoRkFBMDBn&id=8fb5ca7aa1a31f5e @0
05-01 15:58:26.226: I/ChromiumHTTPDataSourceSupport(31648): Server responded with http status 403
05-01 15:58:26.226: I/AwesomePlayer(31648): mConnectingDataSource->connect() returned -1004
05-01 15:58:26.226: E/MediaPlayer(31565): error (1, -1004)
05-01 15:58:26.242: E/MediaPlayer(31565): Error (1,-1004)
05-01 15:58:26.242: E/RS(31565): MediaPlayer Playback ERROR
05-01 15:58:26.242: V/(31565): Media Error, Error Unknown -1004
05-01 15:58:26.242: I/RS(31565): MediaPlayer Playback COMPLETED
I hope you can help. Thanks!
回答1:
1)try without static constructor 2)create a mp object with standard constructor, Try using setDataSource(), prepareAsync() etc. 3)Catch null and illegal state exceptions.
There are some bugs & limitations with MediaPlayer api.
Please ignore isCanceleld() in my sample code.
sample code:
if (mp == null && isCancelled() != true) {
mp = new MediaPlayer();
mp.setDataSource(chnlUrlParam);
mp.prepareAsync();
mp.start();
// Log.d("doInBackground", "mp.getCurrentPosition() after mp.start() "+ mp.getCurrentPosition()); // Log.d("doInBackground","mp.getDuration() after mp.start() " + mp.getDuration()); mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp,
int percent) {
Log.d("TAG_Async", "percent: " + percent);
}
});
}
if (mp == null) {
Log.d(TAG_Async,"### Failed to create media player from static constructor ###");
}
回答2:
Actually there is an error is streaming url error due to which this problem exists.. otherwise it works well in videoview.
you have to add youtube signature after the url.
I worked on that and it works perfectly.
来源:https://stackoverflow.com/questions/10399066/android-streaming-with-mediaplayer-error1-1004-and-3gpp-video