Search in sources :

Example 96 with MediaPlayer

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) {
        }
    });
}
Also used : OnInfoListener(android.media.MediaPlayer.OnInfoListener) SurfaceTexture(android.graphics.SurfaceTexture) OnPreparedListener(android.media.MediaPlayer.OnPreparedListener) Uri(android.net.Uri) Surface(android.view.Surface) MediaPlayer(android.media.MediaPlayer)

Example 97 with MediaPlayer

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);
    }
}
Also used : Uri(android.net.Uri) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 98 with MediaPlayer

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();
    }
}
Also used : File(java.io.File) MediaPlayer(android.media.MediaPlayer)

Example 99 with MediaPlayer

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;
    }
}
Also used : IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 100 with MediaPlayer

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) {
    }
}
Also used : AudioManager(android.media.AudioManager) File(java.io.File) MediaPlayer(android.media.MediaPlayer)

Aggregations

MediaPlayer (android.media.MediaPlayer)370 IOException (java.io.IOException)180 LargeTest (android.test.suitebuilder.annotation.LargeTest)60 AudioEffect (android.media.audiofx.AudioEffect)54 AudioManager (android.media.AudioManager)50 AssetFileDescriptor (android.content.res.AssetFileDescriptor)28 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 MediaRecorder (android.media.MediaRecorder)18 Uri (android.net.Uri)16 SurfaceHolder (android.view.SurfaceHolder)16 CamcorderProfile (android.media.CamcorderProfile)12 File (java.io.File)12 VideoView (android.widget.VideoView)11 Intent (android.content.Intent)8 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)7 Surface (android.view.Surface)7 View (android.view.View)7 MediaController (android.widget.MediaController)7 MediaFormat (android.media.MediaFormat)6 UtteranceProgressDispatcher (android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher)6