How to handle invaid urls in M3U8 in MediaPlayer

Jeggu

New member
Oct 25, 2016
3
0
0
Visit site
I am playing m3u8 files using mediaplyer.

But ckf url which is present in m3u8 is invalid. i have manipulate that url to get response.

How can i handle such cases and serve the response

code:

public class ViewerActivity extends Activity implements Callback, OnPreparedListener, VideoControllerView.MediaPlayerControl{

public static MediaPlayer player;
public static SurfaceView surfaceView;
public static SurfaceHolder surfaceHolder;
VideoControllerView controller;
boolean isPaused = false;
@override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videoviewer);
player = new MediaPlayer();
//controller = new VideoControllerView(this);
surfaceView = (SurfaceView)findViewById(R.id.videoSurface);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
player.setOnPreparedListener(this);

Intent intent = getIntent();
String url = intent.getStringExtra("URL");

try {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(this, Uri.parse(url));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@override
public void onPrepared(MediaPlayer mp)
{
// TODO Auto-generated method stub
int videoWidth = player.getVideoWidth();
int videoHeight = player.getVideoHeight();
android.view.ViewGroup.LayoutParams lp = surfaceView.getLayoutParams();
lp.width = videoWidth;
lp.height = videoHeight;
surfaceView.setLayoutParams(lp);
mp.start();

}
@override
public void surfaceCreated(SurfaceHolder holder) {
player.setDisplay(holder);
if (isPaused) {
player.start();
isPaused = false;
}
else
player.prepareAsync();

}
}
 

Rukbat

Retired Moderator
Feb 12, 2012
44,529
26
0
Visit site
You're mixing 2 things - an inability of the code to access a valid, but syntactically incorrect, URL and an invalid URL. You can't access an invalid URL, any more than you can go to the house between two adjacent houses ("invalid URL" means that there's no authoritative server that has that URL, so you can't get its IP address.)

Could you reword the question?