MediaPlayer setDisplay - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for MediaPlayer setDisplay method.

This code example shows how to use the following methods:setDisplay
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } 
 
    @Override 
    public void setDisplay(SurfaceHolder holder) {
        mMediaPlayer.setDisplay(holder);
        if (holder != null)
            holder.addCallback(mSurfaceCallback);
    } 
 
    private SurfaceHolder.Callback mSurfaceCallback = new Callback() {
        public void surfaceChanged(SurfaceHolder holder, int format, int width, 
                int height) { 
        } 
 
        public void surfaceCreated(SurfaceHolder holder) { 
        } 
 
        public void surfaceDestroyed(SurfaceHolder holder) { 
            if (mMediaPlayer != null) { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepare, setDataSource, setDisplay, start
	@Override 
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub 
		 
		try { 
			mMediaPlayer = new MediaPlayer();
			mMediaPlayer.setDataSource(videoPath);
			mMediaPlayer.setDisplay(holder);
			mMediaPlayer.prepare();
			mMediaPlayer.start();
		} 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) {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepareAsync, setAudioStreamType, setDataSource, setDisplay, setOnPreparedListener
		Log.d(TAG, "Play video on full, path: " + path);
		File videoFile = new File(path);
        FileInputStream fis;
		try { 
			fis = new FileInputStream(videoFile);
	        mMediaPlayer.setDataSource(fis.getFD());
	        mMediaPlayer.setDisplay(sHolder);
	         
	        mMediaPlayer.prepareAsync();
	         
	        mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
				@Override 
				public void onPrepared(MediaPlayer mp) {
					onCancel(); 
					mMediaPlayer.start();
					setSurfaceViewScale(); 
					mMediaPlayer.seekTo(position);
					mc.setMediaPlayer(getMediaPlayerControl());
					mc.setAnchorView(video);
					 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isPlaying, prepare, reset, setAudioStreamType, setDataSource
		 
 
		buttonPlayVideo.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View arg0) {
				pausing = false;
				if (mediaPlayer.isPlaying()) {
					mediaPlayer.reset();
				} 
				mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
				mediaPlayer.setDisplay(holderVideo);
				try { 
					mediaPlayer.setDataSource("/sdcard/video/movie1080.mp4");
					mediaPlayer.prepare();
 
					// mediaPlayer.prepareAsync(); 
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalStateException e) {
					e.printStackTrace();
				} catch (IOException e) {

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setDisplay, setOnBufferingUpdateListener
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setDisplay, setOnBufferingUpdateListener
    } 
     
    private void playVideo() { 
    	try { 
            // Create a new media player and set the listeners 
            mMediaPlayer = new MediaPlayer();
            mMediaPlayer.setDataSource(path);
            mMediaPlayer.setDisplay(holder);
            mMediaPlayer.prepare();
            mMediaPlayer.setOnBufferingUpdateListener(this);
            mMediaPlayer.setOnCompletionListener(this);
            mMediaPlayer.setOnPreparedListener(this);
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    	} catch (Exception e) {
        } 
    } 
     
    public void onPrepared(MediaPlayer mediaplayer) {
        mVideoWidth = mMediaPlayer.getVideoWidth();
        mVideoHeight = mMediaPlayer.getVideoHeight();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepare, setDisplay
	} 
 
	public void surfaceCreated(SurfaceHolder holder) {
		Log.v(LOGTAG, "surfaceCreated Called");
 
		mediaPlayer.setDisplay(holder);
 
		try { 
			mediaPlayer.prepare();
		} catch (IllegalStateException e) {
			Log.v(LOGTAG, e.getMessage());
			finish();
		} catch (IOException e) {
			Log.v(LOGTAG, e.getMessage());
			finish();
		} 
	} 
 
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepareAsync, setDataSource, setDisplay, setOnCompletionListener, setOnPreparedListener
 
	} 
 
	public void surfaceCreated(SurfaceHolder holder) {
		try { 
			mediaPlayer.setDisplay(holder);
			mediaPlayer.setDataSource(videoURL);
			mediaPlayer.setOnPreparedListener(new VideoPlayerPrepareListener(
					this));
			mediaPlayer.setOnCompletionListener(new VideoPlayerOnCompletionListener());
			mediaPlayer.prepareAsync();
 
		} catch (Exception ex) {
			Log.e(TAG, "Video Playback Error. ", ex);
		} 
 
	} 
 
	/** 
	 * Setup the aspect ratio for the SurfaceView 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioStreamType, setDataSource, setDisplay, setOnVideoSizeChangedListener
     * Initializes the media player and prepares it for video playback 
     */ 
    private void prepareMediaPlayer() { 
        if (videoSource != null && mVideoPreview.getHolder().getSurface().isValid()) {
            try { 
                mMediaPlayer = new MediaPlayer();
                mMediaPlayer.setOnVideoSizeChangedListener(mVideoSizeListener);
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_RING); // Use ringer volume
                mMediaPlayer.setDataSource(getActivity(), videoSource);
                mMediaPlayer.setDisplay(mVideoPreview.getHolder());
                mMediaPlayer.prepare();
 
            } 
            catch (IOException e) {
                // TODO Auto-generated catch block 
                e.printStackTrace();
            } 
        } 
    } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:prepare, setDataSource, setDisplay, setOnCompletionListener, start
		playVideo(videoList.get(0));
	} 
 
	private void playVideo(String videoPath) {
		try { 
			mediaPlayer = new MediaPlayer();
			mediaPlayer.setOnCompletionListener(this);
			mediaPlayer.setDisplay(holder);
			mediaPlayer.setDataSource(videoPath);
			mediaPlayer.prepare();
			mediaPlayer.start();
		} catch (IllegalArgumentException e) {
			Log.d("MEDIA_PLAYER", e.getMessage());
		} catch (IllegalStateException e) {
			Log.d("MEDIA_PLAYER", e.getMessage());
		} catch (IOException e) {
			Log.d("MEDIA_PLAYER", e.getMessage());
		} 
 
	} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related MediaPlayer setDisplay Questions & Answers:

setDisplay Method Overview
Sets the SurfaceHolder to use for displaying the video portion of the media.
See Code Examples for other Android MediaPlayer Methods: