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) {
}
});
}
}
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);
}
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;
}
}
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);
}
}
Aggregations