lundi 31 octobre 2016

How to handle invaid urls in M3U8 in MediaPlayer

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();

}
}


from Android Forums at AndroidCentral.com - Ask a Question http://ift.tt/2eTkqY6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire