use of android.media.MediaPlayer in project Fairphone by Kwamecorp.
the class OOBEActivity method setupTheVideo.
private void setupTheVideo() {
RelativeLayout rl = (RelativeLayout) findViewById(R.id.oobeVideoViewGroup);
rl.setVisibility(View.VISIBLE);
mVideo = (VideoView) findViewById(R.id.fp_oobe_video);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.fp_buy_a_phone_start_a_movement);
mVideo.setMediaController(null);
mVideo.requestFocus();
mVideo.setVideoURI(uri);
mVideo.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
mVideo.start();
mVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
stopIntroVideo();
}
});
// button
mSkipVideoButton = (Button) findViewById(R.id.fp_oobe_video_skip_button);
mSkipVideoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
stopIntroVideo();
}
});
}
use of android.media.MediaPlayer in project CircleDemo by Naoki2015.
the class TextureVideoView method openVideo.
private void openVideo() {
if (mUri == null || mSurface == null || mTargetState != STATE_PLAYING) {
// not ready for playback just yet, will try again later
return;
}
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mAudioManager.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();
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnInfoListener(this);
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setDataSource(mContext, mUri);
mMediaPlayer.setSurface(mSurface);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setLooping(false);
mMediaPlayer.prepareAsync();
// we don't set the target state here either, but preserve the
// target state that was there before.
mCurrentState = STATE_PREPARING;
mTargetState = STATE_PREPARING;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
MediaExtractor mediaExtractor = new MediaExtractor();
mediaExtractor.setDataSource(mContext, mUri, null);
MediaFormat format;
mHasAudio = false;
for (int i = 0; i < mediaExtractor.getTrackCount(); i++) {
format = mediaExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("audio/")) {
mHasAudio = true;
break;
}
}
} else {
mHasAudio = true;
}
} catch (IOException ex) {
if (SHOW_LOGS)
Log.w(TAG, "Unable to open content: " + mUri, ex);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaPlayerCallback != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (mMediaPlayerCallback != null) {
mMediaPlayerCallback.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
}
}
});
}
} catch (IllegalArgumentException ex) {
if (SHOW_LOGS)
Log.w(TAG, "Unable to open content: " + mUri, ex);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
if (mMediaPlayerCallback != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (mMediaPlayerCallback != null) {
mMediaPlayerCallback.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
}
}
});
}
}
}
use of android.media.MediaPlayer in project LuaViewSDK by alibaba.
the class UDAudio method play.
/**
* start playing audio
*
* @param uriOrName
* @param loopTimes
* @return
*/
public synchronized UDAudio play(String uriOrName, Integer loopTimes) {
stopAndReset();
if (uriOrName != null && uriOrName.equals(this.mUriOrName) == false) {
//url 不同
this.mUriOrName = uriOrName;
}
if (loopTimes != null) {
this.mLoopTimes = loopTimes;
}
if (this.mUriOrName != null) {
final MediaPlayer player = getMediaPlayer();
if (player != null && player.isPlaying() == false) {
String uri = null;
boolean assetFileExist = false;
if (URLUtil.isNetworkUrl(this.mUriOrName) || URLUtil.isFileUrl(this.mUriOrName) || URLUtil.isAssetUrl(this.mUriOrName)) {
//net & file & asset
uri = this.mUriOrName;
} else {
//plain text, use as file path
uri = getLuaResourceFinder().buildFullPathInBundleOrAssets(this.mUriOrName);
assetFileExist = AssetUtil.exists(getContext(), uri);
}
try {
if (assetFileExist) {
final AssetFileDescriptor descriptor = getContext().getAssets().openFd(uri);
player.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
} else {
player.setDataSource(uri);
}
player.setOnErrorListener(this);
player.setOnCompletionListener(this);
player.setOnPreparedListener(this);
player.setLooping((this.mLoopTimes != null && this.mLoopTimes > 1) ? true : false);
player.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return this;
}
use of android.media.MediaPlayer in project Notes by MiCode.
the class AlarmAlertActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
}
Intent intent = getIntent();
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) : mSnippet;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return;
}
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();
playAlarmSound();
} else {
finish();
}
}
use of android.media.MediaPlayer in project actor-platform by actorapp.
the class AndroidPlayerActor method onPlayMessage.
protected void onPlayMessage(String fileName) {
currentFileName = fileName;
destroyPlayer();
state = STATE_NONE;
try {
mplayer = new MediaPlayer();
mplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mplayer.setDataSource(context, Uri.fromFile(new File(currentFileName)));
mplayer.prepare();
mplayer.setLooping(false);
mplayer.start();
mplayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
self().send(new Stop());
}
});
mplayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
self().send(new Error());
return false;
}
});
} catch (Exception e) {
destroyPlayer();
callback.onError(currentFileName);
return;
}
callback.onStart(currentFileName);
schedule(new Notify(), 500);
state = STATE_STARTED;
}
Aggregations