Search in sources :

Example 11 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project VitamioBundle by yixia.

the class VideoViewSubtitle method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.subtitle2);
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    mSubtitleView = (TextView) findViewById(R.id.subtitle_view);
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewSubtitle.this, "Please edit VideoViewSubtitle Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
			 * Alternatively,for streaming media you can use
			 * mVideoView.setVideoURI(Uri.parse(URLstring));
			 */
        mVideoView.setVideoPath(path);
        // mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                mediaPlayer.setPlaybackSpeed(1.0f);
                mVideoView.addTimedTextSource(subtitle_path);
                mVideoView.setTimedTextShown(true);
            }
        });
        mVideoView.setOnTimedTextListener(new OnTimedTextListener() {

            @Override
            public void onTimedText(String text) {
                mSubtitleView.setText(text);
            }

            @Override
            public void onTimedTextUpdate(byte[] pixels, int width, int height) {
            }
        });
    }
}
Also used : OnTimedTextListener(io.vov.vitamio.MediaPlayer.OnTimedTextListener) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 12 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project ABPlayer by winkstu.

the class PlayerService method vplayerInit.

private void vplayerInit(boolean isHWCodec) {
    mPlayer = new MediaPlayer(PlayerService.this.getApplicationContext(), isHWCodec);
    mPlayer.setOnHWRenderFailedListener(new OnHWRenderFailedListener() {

        @Override
        public void onFailed() {
            if (mListener != null)
                mListener.onHWRenderFailed();
        }
    });
    mPlayer.setOnBufferingUpdateListener(PlayerService.this);
    mPlayer.setOnCompletionListener(PlayerService.this);
    mPlayer.setOnPreparedListener(PlayerService.this);
    mPlayer.setOnVideoSizeChangedListener(PlayerService.this);
    mPlayer.setOnErrorListener(PlayerService.this);
    mPlayer.setOnInfoListener(PlayerService.this);
}
Also used : OnHWRenderFailedListener(io.vov.vitamio.MediaPlayer.OnHWRenderFailedListener) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 13 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project ABPlayer by winkstu.

the class VideoView method openVideo.

private void openVideo() {
    if (mUri == null || mSurfaceHolder == null || !Vitamio.isInitialized(mContext))
        return;
    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);
    release(false);
    try {
        mDuration = -1;
        mCurrentBufferPercentage = 0;
        mMediaPlayer = new MediaPlayer(mContext);
        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
        mMediaPlayer.setOnTimedTextListener(mTimedTextListener);
        mMediaPlayer.setDataSource(mContext, mUri);
        mMediaPlayer.setDisplay(mSurfaceHolder);
        mMediaPlayer.setScreenOnWhilePlaying(true);
        mMediaPlayer.prepareAsync();
        mCurrentState = STATE_PREPARING;
        attachMediaController();
    } catch (IOException ex) {
        Log.e("Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
        return;
    } catch (IllegalArgumentException ex) {
        Log.e("Unable to open content: " + mUri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
        return;
    }
}
Also used : Intent(android.content.Intent) IOException(java.io.IOException) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 14 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project ABPlayer by winkstu.

the class MediaPlayerDemo_Audio method playAudio.

private void playAudio(Integer media) {
    try {
        switch(media) {
            case LOCAL_AUDIO:
                /**
                 * TODO: Set the path variable to a local audio file path.
                 */
                path = "";
                if (path == "") {
                    // Tell the user to provide an audio file URL.
                    Toast.makeText(MediaPlayerDemo_Audio.this, "Please edit MediaPlayer_Audio Activity, " + "and set the path variable to your audio file path." + " Your audio file must be stored on sdcard.", Toast.LENGTH_LONG).show();
                    return;
                }
                mMediaPlayer = new MediaPlayer(this);
                mMediaPlayer.setDataSource(path);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
                break;
            case RESOURCES_AUDIO:
                /**
                 * TODO: Upload a audio file to res/raw folder and provide its resid in
                 * MediaPlayer.create() method.
                 */
                // Bug need fixed
                mMediaPlayer = createMediaPlayer(this, R.raw.test_cbr);
                mMediaPlayer.start();
        }
        tx.setText("Playing audio...");
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) MediaPlayer(io.vov.vitamio.MediaPlayer)

Aggregations

MediaPlayer (io.vov.vitamio.MediaPlayer)14 IOException (java.io.IOException)7 Intent (android.content.Intent)2 AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 MediaController (io.vov.vitamio.widget.MediaController)2 SuppressLint (android.annotation.SuppressLint)1 Surface (android.view.Surface)1 OnHWRenderFailedListener (io.vov.vitamio.MediaPlayer.OnHWRenderFailedListener)1 OnTimedTextListener (io.vov.vitamio.MediaPlayer.OnTimedTextListener)1