Java Code Examples for android.media.MediaPlayer#setOnVideoSizeChangedListener()

The following examples show how to use android.media.MediaPlayer#setOnVideoSizeChangedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoViewerActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
private void playVideo(Uri uri) {
doCleanUp();
try {


  // Create a new media player and set the listeners
  mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource(this, uri);
  mMediaPlayer.setDisplay(holder);
  mMediaPlayer.prepare();
  mMediaPlayer.setOnBufferingUpdateListener(this);
  mMediaPlayer.setOnCompletionListener(this);
  mMediaPlayer.setOnPreparedListener(this);
  mMediaPlayer.setOnVideoSizeChangedListener(this);
  mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

} catch (Exception e) {
  Log.e(TAG, "error: " + e.getMessage(), e);
}
}
 
Example 2
Source File: VideoViewRecycler.java    From MaterialDesignSupport with MIT License 6 votes vote down vote up
public void startCurrentPlayback() {
    if (mIsSurfaceCreated == false) {
        mIsPendingPlayback = true;
        return;
    }

    stopCurrentPlayback();

    try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDisplay(getHolder());
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setDataSource(mContext, Uri.parse(mResourcePath));
        mMediaPlayer.prepareAsync();
    } catch (Exception e) {
        Log.i("VideoRow", "Issue trying to set the display!");
    }
}
 
Example 3
Source File: GuideFragment.java    From LefishGuide with Apache License 2.0 6 votes vote down vote up
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
    Surface surface = new Surface(surfaceTexture);
    try {
        int id = getArguments().getInt("Id");
        /**
         * mMediaPlayer = MediaPlayer.create(getContext(), R.raw.guide_one);
         * 创建实例是不行的,我也没有明白为什么
         */
        mMediaPlayer = new MediaPlayer();
        Uri video = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + RES.get(id));
        mMediaPlayer.setDataSource(getContext(), video);

        mMediaPlayer.setSurface(surface);
        mMediaPlayer.prepare();
        mMediaPlayer.setLooping(false);
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: AndroidMediaPlayerFacade.java    From no-player with Apache License 2.0 6 votes vote down vote up
private MediaPlayer createAndBindMediaPlayer(Either<Surface, SurfaceHolder> surface,
                                             Uri videoUri) throws IOException, IllegalStateException, IllegalArgumentException {
    MediaPlayer mediaPlayer = mediaPlayerCreator.createMediaPlayer();
    mediaPlayer.setOnPreparedListener(internalPreparedListener);
    mediaPlayer.setOnVideoSizeChangedListener(internalSizeChangedListener);
    mediaPlayer.setOnCompletionListener(internalCompletionListener);
    mediaPlayer.setOnErrorListener(internalErrorListener);
    mediaPlayer.setOnBufferingUpdateListener(internalBufferingUpdateListener);
    mediaPlayer.setDataSource(context, videoUri, NO_HEADERS);
    attachSurface(mediaPlayer, surface);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setScreenOnWhilePlaying(true);

    currentBufferPercentage = 0;
    volume = 1.0f;

    return mediaPlayer;
}
 
Example 5
Source File: MediaPlayerActivity.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void playVideo() {
    mProgressBar.setVisibility(View.VISIBLE);
    doCleanUp();
    try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(mUrl);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: MediaPlayerActivity.java    From SendBird-Android with MIT License 6 votes vote down vote up
private void playVideo() {
    mProgressBar.setVisibility(View.VISIBLE);
    doCleanUp();
    try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(mUrl);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: JZMediaSystem.java    From JZVideoDemo with MIT License 5 votes vote down vote up
@Override
public void prepare() {
    try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        if (dataSourceObjects.length > 1) {
            mediaPlayer.setLooping((boolean) dataSourceObjects[1]);
        }
        mediaPlayer.setOnPreparedListener(JZMediaSystem.this);
        mediaPlayer.setOnCompletionListener(JZMediaSystem.this);
        mediaPlayer.setOnBufferingUpdateListener(JZMediaSystem.this);
        mediaPlayer.setScreenOnWhilePlaying(true);
        mediaPlayer.setOnSeekCompleteListener(JZMediaSystem.this);
        mediaPlayer.setOnErrorListener(JZMediaSystem.this);
        mediaPlayer.setOnInfoListener(JZMediaSystem.this);
        mediaPlayer.setOnVideoSizeChangedListener(JZMediaSystem.this);
        mediaPlayer.setVolume(0f, 0f);
        Class<MediaPlayer> clazz = MediaPlayer.class;
        Method method = clazz.getDeclaredMethod("setDataSource", String.class, Map.class);
        if (dataSourceObjects.length > 2) {
            method.invoke(mediaPlayer, currentDataSource.toString(), dataSourceObjects[2]);
        } else {
            method.invoke(mediaPlayer, currentDataSource.toString(), null);
        }
        mediaPlayer.prepareAsync();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: GPlayer.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gplayer);
    mAudioManager = (AudioManager) getSystemService(Service.AUDIO_SERVICE);

    surfaceView = (SurfaceView) findViewById(R.id.gplayer_surfaceview);
    surfaceHolder = surfaceView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mMediaPlayer = new MediaPlayer();

    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnErrorListener(this);
    mMediaPlayer.setOnInfoListener(this);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnSeekCompleteListener(this);
    mMediaPlayer.setOnVideoSizeChangedListener(this);

    initControl();

    Intent intent = getIntent();
    playURI = intent.getStringExtra("playURI");
    if (!TextUtils.isEmpty(playURI)) {
        setUri(playURI);
    }

    setTitle(intent);
    currentDisplay = getWindowManager().getDefaultDisplay();

    registerBrocast();
}
 
Example 9
Source File: NativeVideoDelegate.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
protected void initMediaPlayer() {
    mediaPlayer = new MediaPlayer();

    mediaPlayer.setOnInfoListener(internalListeners);
    mediaPlayer.setOnErrorListener(internalListeners);
    mediaPlayer.setOnPreparedListener(internalListeners);
    mediaPlayer.setOnCompletionListener(internalListeners);
    mediaPlayer.setOnSeekCompleteListener(internalListeners);
    mediaPlayer.setOnBufferingUpdateListener(internalListeners);
    mediaPlayer.setOnVideoSizeChangedListener(internalListeners);

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setScreenOnWhilePlaying(true);
}
 
Example 10
Source File: VideoView.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
        // not ready for playback just yet, will try again later
        return;
    }
    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);
    try {
        mMediaPlayer = new MediaPlayer();
        if (mAudioSession != 0) {
            mMediaPlayer.setAudioSessionId(mAudioSession);
        } else {
            mAudioSession = mMediaPlayer.getAudioSessionId();
        }
        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mCurrentBufferPercentage = 0;
        mMediaPlayer.setLooping(mLooping);
        mMediaPlayer.setDataSource(getContext(), mUri);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setScreenOnWhilePlaying(true);
        mMediaPlayer.prepareAsync();

        // we don't set the target state here either, but preserve the
        // target state that was there before.
        mCurrentState = STATE_PREPARING;
        attachMediaController();
    } catch (Exception ex) {
        Log.w(TAG, "Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    }
}
 
Example 11
Source File: SystemImplMediaPlayer.java    From android-jungle-mediaplayer with Apache License 2.0 5 votes vote down vote up
private void init() {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnErrorListener(mOnErrorListener);
    mMediaPlayer.setOnPreparedListener(mOnPreparedListener);
    mMediaPlayer.setOnCompletionListener(mOnCompletionListener);
    mMediaPlayer.setOnSeekCompleteListener(mOnSeekCompletionListener);
    mMediaPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
    mMediaPlayer.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener);
}
 
Example 12
Source File: PanoMediaPlayerWrapper.java    From Pano360 with MIT License 5 votes vote down vote up
public PanoMediaPlayerWrapper() {
    mMediaPlayer=new MediaPlayer();
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setOnErrorListener(this);
    mMediaPlayer.setOnVideoSizeChangedListener(this);
    mMediaPlayer.setOnInfoListener(this);
    mMediaPlayer.setOnBufferingUpdateListener(this);
}
 
Example 13
Source File: VideoView.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
private void openVideo() {
    if (mUri == null || mInputSurfaceHolder == null) {
        // not ready for playback yet, will be called again later
        return;
    }

    release();

    try {
        mPlayer = new MediaPlayer();
        mPlayer.setSurface(getInputHolder().getSurface());
        mPlayer.setOnPreparedListener(mPreparedListener);
        mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
        mPlayer.setOnCompletionListener(mCompletionListener);
        mPlayer.setOnErrorListener(mErrorListener);
        mPlayer.setOnInfoListener(mInfoListener);
        mPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mCurrentBufferPercentage = 0;
        mPlayer.setDataSource(getContext(), mUri, mHeaders);
        mCurrentState = STATE_PREPARING;
        mPlayer.prepareAsync();
    } catch (Exception e) {
        Log.e(TAG, "video open failed", e);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    }
}
 
Example 14
Source File: VideoViewTV.java    From letv with Apache License 2.0 5 votes vote down vote up
private void deadListener(MediaPlayer mMediaPlayer) {
    if (mMediaPlayer != null) {
        mMediaPlayer.setOnSeekCompleteListener(null);
        mMediaPlayer.setOnInfoListener(null);
        mMediaPlayer.setOnPreparedListener(null);
        mMediaPlayer.setOnVideoSizeChangedListener(null);
        mMediaPlayer.setOnCompletionListener(null);
        mMediaPlayer.setOnErrorListener(null);
        mMediaPlayer.setOnBufferingUpdateListener(null);
    }
}
 
Example 15
Source File: AndroidMediaPlayer.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void initPlayer() {
    mMediaPlayer = new MediaPlayer();
    setOptions();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnErrorListener(onErrorListener);
    mMediaPlayer.setOnCompletionListener(onCompletionListener);
    mMediaPlayer.setOnInfoListener(onInfoListener);
    mMediaPlayer.setOnBufferingUpdateListener(onBufferingUpdateListener);
    mMediaPlayer.setOnPreparedListener(onPreparedListener);
    mMediaPlayer.setOnVideoSizeChangedListener(onVideoSizeChangedListener);
}
 
Example 16
Source File: OBVideoPlayer.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void prepareForPlaying(AssetFileDescriptor afd, long atTime, OBUtils.RunLambda seekCompletion)
{
    if(afd == null || activityPaused )
        return;

    playAfterPrepare = false;
    condition = playerLock.newCondition();
    fromTime = atTime;

    if(seekCompletion != null)
        this.seekCompletionBlock = seekCompletion;

    player = new MediaPlayer();
    player.setSurface(surface);
    //surface.release();
    player.setOnPreparedListener(this);
    player.setOnCompletionListener(this);
    player.setOnSeekCompleteListener(this);
    player.setOnErrorListener(this);
    player.setOnVideoSizeChangedListener(this);

    try
    {
        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        player.prepareAsync();

    }
    catch (Exception e)
    {
        e.printStackTrace();
        return;
    }
}
 
Example 17
Source File: OBVideoPlayer.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public void startPlayingAtTime(AssetFileDescriptor afd, long fr, MediaPlayer.OnPreparedListener preparedListener, MediaPlayer.OnCompletionListener completionListener)
{
    if(afd == null || activityPaused )
        return;

    condition = playerLock.newCondition();
    fromTime = fr;

    player = new MediaPlayer();
    player.setSurface(surface);
    //surface.release();
    player.setOnPreparedListener(preparedListener);
    player.setOnCompletionListener(completionListener);
    player.setOnSeekCompleteListener(this);
    player.setOnErrorListener(this);
    player.setOnVideoSizeChangedListener(this);
    try
    {
        player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        player.prepareAsync();

    }
    catch (Exception e)
    {
        e.printStackTrace();
        return;
    }
}
 
Example 18
Source File: UniversalVideoView.java    From LLApp with Apache License 2.0 4 votes vote down vote up
private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
        // not ready for playback just yet, will try again later
        return;
    }
    AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);
    try {
        mMediaPlayer = new MediaPlayer();

        if (mAudioSession != 0) {
            mMediaPlayer.setAudioSessionId(mAudioSession);
        } else {
            mAudioSession = mMediaPlayer.getAudioSessionId();
        }
        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mCurrentBufferPercentage = 0;
        mMediaPlayer.setDataSource(mContext, mUri);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setScreenOnWhilePlaying(true);
        mMediaPlayer.prepareAsync();


        // we don't set the target state here either, but preserve the
        // target state that was there before.
        mCurrentState = STATE_PREPARING;
        attachMediaController();
    } catch (IOException ex) {
        Log.w(TAG, "Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
    }
}
 
Example 19
Source File: AssetVideoView.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void openVideo() {
    if (mFileDescriptor == null || mSurfaceHolder == null) {
        // not ready for playback just yet, will try again later
        return;
    }
    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);

    AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

    try {
        mMediaPlayer = new MediaPlayer();

        if (mAudioSession != 0) {
            mMediaPlayer.setAudioSessionId(mAudioSession);
        } else {
            mAudioSession = mMediaPlayer.getAudioSessionId();
        }
        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mCurrentBufferPercentage = 0;
        mMediaPlayer.setDataSource(mFileDescriptor, mStartOffset, mLength);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setScreenOnWhilePlaying(true);
        mMediaPlayer.prepareAsync();


        // we don't set the target state here either, but preserve the
        // target state that was there before.
        mCurrentState = STATE_PREPARING;
        attachMediaController();
    } catch (IOException | IllegalArgumentException ex) {
        Log.w(TAG, "Unable to open content: " + mFileDescriptor, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
        return;
    }
}
 
Example 20
Source File: MediaPlayerDemo_Video.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
private void playVideo(Integer Media) {
    doCleanUp();
    try {

        switch (Media) {
            case LOCAL_VIDEO:
                /*
                 * TODO: Set the path variable to a local media file path.
                 */
                path = "";
                if (path == "") {
                    // Tell the user to provide a media file URL.
                    Toast
                            .makeText(
                                    MediaPlayerDemo_Video.this,
                                    "Please edit MediaPlayerDemo_Video Activity, "
                                            + "and set the path variable to your media file path."
                                            + " Your media file must be stored on sdcard.",
                                    Toast.LENGTH_LONG).show();

                }
                break;
            case STREAM_VIDEO:
                /*
                 * TODO: Set path variable to progressive streamable mp4 or
                 * 3gpp format URL. Http protocol should be used.
                 * Mediaplayer can only play "progressive streamable
                 * contents" which basically means: 1. the movie atom has to
                 * precede all the media data atoms. 2. The clip has to be
                 * reasonably interleaved.
                 * 
                 */
                path = "";
                if (path == "") {
                    // Tell the user to provide a media file URL.
                    Toast
                            .makeText(
                                    MediaPlayerDemo_Video.this,
                                    "Please edit MediaPlayerDemo_Video Activity,"
                                            + " and set the path variable to your media file URL.",
                                    Toast.LENGTH_LONG).show();

                }

                break;


        }

        // 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.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);


    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}