Code example for MediaPlayer: Playing audio and video

Methods: prepareresetsetDataSourcestart

0
	MediaPlayer player;
	 
	@Override 
	public IBinder onBind(Intent intent) {
		Log.d(TAG, "onBind");
		player.reset();
		 
		Toast.makeText(this, "Connecting ...", Toast.LENGTH_LONG).show();
		 
		try { 
			player.setDataSource(intent.getStringExtra("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();
		} 
		 
		 
		try { 
			player.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		 
		player.start();
		 
		Toast.makeText(this, "Listening to " + intent.getStringExtra("name"), Toast.LENGTH_LONG).show();
		 
		return null; 
	} 
Contextual code suggestions in your IDE  Get Codota for Java