use of android.media.MediaPlayer in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class FingerprintLocationAnimationVideoView method onFinishInflate.
@Override
protected void onFinishInflate() {
super.onFinishInflate();
setSurfaceTextureListener(new SurfaceTextureListener() {
private SurfaceTexture mTextureToDestroy = null;
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
setVisibility(View.INVISIBLE);
Uri videoUri = getFingerprintLocationAnimation();
if (mMediaPlayer != null) {
mMediaPlayer.release();
}
if (mTextureToDestroy != null) {
mTextureToDestroy.release();
mTextureToDestroy = null;
}
mMediaPlayer = MediaPlayer.create(mContext, videoUri);
mMediaPlayer.setSurface(new Surface(surfaceTexture));
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setLooping(true);
}
});
mMediaPlayer.setOnInfoListener(new OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
// Keep the view hidden until video starts
setVisibility(View.VISIBLE);
}
return false;
}
});
mAspect = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth();
requestLayout();
startAnimation();
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
mTextureToDestroy = surfaceTexture;
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
});
}
use of android.media.MediaPlayer in project android_frameworks_base by ResurrectionRemix.
the class LocalRenderer method setNextContent.
@Override
public void setNextContent(Bundle request) {
String source = request.getString(RequestUtils.EXTRA_KEY_SOURCE);
// request.mHeaders;
Map<String, String> headers = null;
if (DEBUG) {
Log.d(TAG, mDebugId + ": Setting next content. Have player? " + (mPlayer != null) + " have next player? " + (mNextPlayer != null));
}
if (mPlayer == null) {
// set a next.
return;
}
if (mNextPlayer != null) {
// Before setting up the new one clear out the old one and release
// it to ensure it doesn't play.
mPlayer.setNextMediaPlayer(null);
mNextPlayer.release();
mNextPlayer = null;
mNextContent = null;
}
if (source == null) {
// If there's no new content we're done
return;
}
final MediaPlayer newPlayer = new MediaPlayer();
try {
if (headers != null) {
Uri sourceUri = Uri.parse(source);
newPlayer.setDataSource(mContext, sourceUri, headers);
} else {
newPlayer.setDataSource(source);
}
} catch (Exception e) {
newPlayer.release();
// Don't return an error until we get to this item in playback
return;
}
if (preparePlayer(newPlayer, false)) {
mPlayer.setNextMediaPlayer(newPlayer);
mNextPlayer = newPlayer;
mNextContent = new PlayerContent(source, headers);
}
}
use of android.media.MediaPlayer in project ride-read-android by Ride-Read.
the class VideoTextureView method startMediaPlayer.
public void startMediaPlayer() {
if (isPlaying || !isSurfaceTextureAvailable)
return;
// }
try {
if (true)
mediaPlayer = MediaPlayer.create(getContext(), R.raw.test);
else {
final File file = new File(videoPath);
if (!file.exists()) {
//文件不存在
Toast.makeText(getContext(), "视频不存在", Toast.LENGTH_SHORT).show();
return;
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(file.getAbsolutePath());
}
mediaPlayer.setSurface(surface);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//设置左右音道的声音为0
mediaPlayer.setVolume(1, 1);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
showIvTip(false);
isPlaying = true;
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
stopMediaPlayer();
}
});
mediaPlayer.prepare();
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.media.MediaPlayer in project react-native-android-video-editor by RZulfikri.
the class VideoSurfaceView method onHostResume.
@Override
public void onHostResume() {
if (onPaused) {
try {
if (mMediaPlayer == null) {
// Log.e("DEBUG", "MASUK NULL");
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(videoUri);
mRenderer.setMediaPlayer(mMediaPlayer);
}
// else{
// if(!mMediaPlayer.isPlaying()){
// mMediaPlayer.start();
// }
// }
} catch (Exception e) {
// Log.e("DEBUG", "ERROR = "+e.toString());
}
// onPaused = false;
}
}
use of android.media.MediaPlayer in project wechat by motianhuo.
the class VoicePlayClickListener method playVoice.
public void playVoice(String filePath) {
if (!(new File(filePath).exists())) {
return;
}
((ChatActivity) activity).playMsgId = message.getMsgId();
AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
mediaPlayer = new MediaPlayer();
if (EMChatManager.getInstance().getChatOptions().getUseSpeaker()) {
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
} else {
// 关闭扬声器
audioManager.setSpeakerphoneOn(false);
// 把声音设定成Earpiece(听筒)出来,设定为正在通话中
audioManager.setMode(AudioManager.MODE_IN_CALL);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
}
try {
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mediaPlayer.release();
mediaPlayer = null;
// stop animation
stopPlayVoice();
}
});
isPlaying = true;
currentPlayListener = this;
mediaPlayer.start();
showAnimation();
// 如果是接收的消息
if (message.direct == EMMessage.Direct.RECEIVE) {
try {
if (!message.isAcked) {
message.isAcked = true;
// 告知对方已读这条消息
if (chatType != ChatType.GroupChat)
EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
}
} catch (Exception e) {
message.isAcked = false;
}
if (!message.isListened() && iv_read_status != null && iv_read_status.getVisibility() == View.VISIBLE) {
// 隐藏自己未播放这条语音消息的标志
iv_read_status.setVisibility(View.INVISIBLE);
EMChatManager.getInstance().setMessageListened(message);
}
}
} catch (Exception e) {
}
}
Aggregations