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

The following examples show how to use android.media.MediaPlayer#setOnInfoListener() . 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: MediaPlayerImpl.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public MediaPlayerImpl(Context context, PlayerAttributes attributes) {
    super(context, attributes);
    synchronized (LOCK) {
        mPlayer = new MediaPlayer();
    }
    mContext = context.getApplicationContext();
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    mPlayer.setOnCompletionListener(this);
    mPlayer.setOnErrorListener(this);
    mPlayer.setOnInfoListener(this);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnSeekCompleteListener(this);
    mPlayer.setOnVideoSizeChangedListener(this);
    mPlayer.setOnBufferingUpdateListener(this);
}
 
Example 2
Source File: SuperVideoPlayer.java    From AndroidVideoPlayer with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
    mediaPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            /*
             * add what == MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING
             * fix : return what == 700 in Lenovo low configuration Android System
             */
            if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START
                    || what == MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING) {
                mProgressBarView.setVisibility(View.GONE);
                setCloseButton(true);
                initDLNAInfo();
                return true;
            }
            return false;
        }
    });

}
 
Example 3
Source File: AndroidAudioPlayer.java    From AntennaPod-AudioPlayer with Apache License 2.0 6 votes vote down vote up
public AndroidAudioPlayer(org.antennapod.audio.MediaPlayer owningMediaPlayer, Context context) {
    super(owningMediaPlayer, context);

    mp = new MediaPlayer();
    if (mp == null) {
        throw new IllegalStateException("Did not instantiate MediaPlayer successfully");
    }

    mp.setOnBufferingUpdateListener(this.onBufferingUpdateListener);
    mp.setOnCompletionListener(this.onCompletionListener);
    mp.setOnErrorListener(this.onErrorListener);
    mp.setOnInfoListener(this.onInfoListener);
    Log.d(AMP_TAG, "Setting prepared listener to this.onPreparedListener");
    mp.setOnPreparedListener(this.onPreparedListener);
    mp.setOnSeekCompleteListener(this.onSeekCompleteListener);
}
 
Example 4
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 5
Source File: StandardMediaPlayer.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
public StandardMediaPlayer() {
    try {
        mNextMediaPlayerRef = new WeakReference<StandardMediaPlayer>(null);
        mUsingNuPlayer = NuPlayerDetector.isUsingNuPlayer();
        mHandler = new InternalHandler(this);

        mState = new MediaPlayerStateManager();

        mPlayer = new MediaPlayer();
        mSuperEventHandler = new WeakReference<Handler>(obtainSuperMediaPlayerInternalEventHandler(mPlayer));

        if (LOCAL_LOGD) {
            Log.d(TAG, "[" + System.identityHashCode(mPlayer) + "] Create MediaPlayer instance");
        }

        mPlayer.setOnCompletionListener(mHookOnCompletionListener);
        mPlayer.setOnPreparedListener(mHookOnPreparedListener);
        mPlayer.setOnSeekCompleteListener(mHookOnSeekCompleteListener);
        mPlayer.setOnBufferingUpdateListener(mHookOnBufferingUpdateListener);
        mPlayer.setOnInfoListener(mHookOnInfoListener);
        mPlayer.setOnErrorListener(mHookOnErrorListener);
    } catch (Exception e) {
        Log.e(TAG, makeUnexpectedExceptionCaughtMessage("StandardMediaPlayer()"), e);
        // call release() method to transit to END state
        releaseInternal();
    }
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
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 12
Source File: PictureVideoPlayActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
public void onPrepared(MediaPlayer mp) {
    mp.setOnInfoListener((mp1, what, extra) -> {
        if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
            // video started
            mVideoView.setBackgroundColor(Color.TRANSPARENT);
            return true;
        }
        return false;
    });
}
 
Example 13
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 14
Source File: VideoOutputActivity.java    From SimpleVideoEdit with Apache License 2.0 5 votes vote down vote up
private void setMediaPlayer() {
    player = new MediaPlayer();
    player.setOnCompletionListener(this);
    player.setOnInfoListener(this);
    player.setOnPreparedListener(this);
    try {
        player.setDataSource(mSVE.getAllInputClips().get(0).getClipPath());
        player.prepare();
        player.start();
    } catch (IOException e) {

    }
}
 
Example 15
Source File: AndroidMediaPlayer.java    From K-Sonic with MIT License 4 votes vote down vote up
public AndroidMediaPlayer(com.aocate.media.MediaPlayer owningMediaPlayer, Context context) {
        super(owningMediaPlayer, context);

        mp = new MediaPlayer();

//		final ReentrantLock lock = new ReentrantLock();
//		Handler handler = new Handler(Looper.getMainLooper()) {
//            @Override
//            public void handleMessage(Message msg) {
//            	Log.d(AMP_TAG, "Instantiating new AndroidMediaPlayer from Handler");
//            	lock.lock();
//            	if (mp == null) {
//            		mp = new MediaPlayer();
//            	}
//            	lock.unlock();
//            }
//        };
//		
//        long endTime = System.currentTimeMillis() + TIMEOUT_DURATION_MS;
//        
//        while (true) {
//        	// Retry messages until mp isn't null or it's time to give up
//        	handler.sendMessage(handler.obtainMessage());
//        	if ((mp != null)
//        		|| (endTime < System.currentTimeMillis())) {
//        		break;
//        	}
//        	try {
//				Thread.sleep(50);
//			} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//        }

        if (mp == null) {
            throw new IllegalStateException("Did not instantiate android.media.MediaPlayer successfully");
        }

        mp.setOnBufferingUpdateListener(this.onBufferingUpdateListener);
        mp.setOnCompletionListener(this.onCompletionListener);
        mp.setOnErrorListener(this.onErrorListener);
        mp.setOnInfoListener(this.onInfoListener);
        Log.d(AMP_TAG, " ++++++++++++++++++++++++++++++++ Setting prepared listener to this.onPreparedListener");
        mp.setOnPreparedListener(this.onPreparedListener);
        mp.setOnSeekCompleteListener(this.onSeekCompleteListener);
    }
 
Example 16
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 17
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;
    }
}