Android streaming using MediaPlayer: error (1, -1004) and 3GPP video

I am trying to make a video playback application. I have 2 problems:

1) I have a Youtube link: rtsp: // and I do:

"Uri myUri = Uri.parse (link); // link = rtsp: // ... mMediaPlayer.setDataSource (getApplicationContext (), myUri);"

Then the video does not play ... however, if I use a "video-visual" work. I think the problem is that the "media player" does not play the mpeg codec. Any ideas?

2) I have several links to a different quality, and I connect them to Wi-Fi without any problems, 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% 3Dcpp % 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://oo.preferred.mad01s04.v16.lscache3.c.youtube.com/videoplayback?upn=35Zn4tL7Ibc&sparams= f% 2Cid% 2Cip % 2Cipbits% 2Citag% 2Cratebypass% 2Csource% 2Cupn% 2Cexpire & Fexp = 900147 & ITAG = 18 & = 85.0.0.0 & Signature = AACE528D596873408192BCDDF4ECFC7DDFD68EBB.575689C34D97BA9DE78B375 & amp; & key = yt1 & ipbits = 8 & cf = U0hSSllLUV9MUkNOMl9RRVVEOnduVjJoRkFBMDBn & ID = 8fb5ca7aa1a31f5e ')

05-01 15: 58: 25.484: V / ChromiumHTTPDataSource (31648): connect as uid 10101

05-01 15: 58: 25.484: I / ChromiumHTTPDataSource (31648): connect to http://oo.preferred.mad01s04.v16.lscache3.c.youtube.com/videoplayback?upn=35Zn4tL7Ibc&sparams=cp%2Cid%2Cip% 2Cipbits% 2Citag% 2Cratebypass% 2Csource% 2Cupn% 2Cexpire & fexp = 900,147 & 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): the server responded with an HTTP status of 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): Playing MediaPlayer ERROR

05-01 15: 58: 26.242: V / (31565): media error, unknown error -1004

05-01 15: 58: 26.242: I / RS (31565): MediaPlayer COMPLETED playback

I hope you can help. Thanks!

+1
source share
2 answers

1) try without a static constructor 2) create an mp object with a standard constructor, try using setDataSource (), prepareAsync (), etc. 3) Exclude exceptions and illegal exceptions.

There are some errors and limitations in the MediaPlayer api.

Please ignore isCanceleld () in my sample code.

code example:

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 ###"); } 
0
source

Actually, there is an error related to the URL streaming error due to which this problem exists. Otherwise, it works well in a video ad.

you need to add youtube signature after the url.

I worked on this and it works great.

0
source

Source: https://habr.com/ru/post/1258165/


All Articles