Search in sources :

Example 41 with MediaPlayer

use of android.media.MediaPlayer in project kickmaterial by byoutline.

the class VideoActivity method setDataFromArgs.

private void setDataFromArgs() {
    Intent intent = getIntent();
    if (intent == null) {
        // NOI18E
        LogUtils.LOGE(TAG, "Null intent");
        return;
    }
    Bundle args = intent.getExtras();
    if (args == null) {
        // NOI18E
        LogUtils.LOGE(TAG, "Null args");
        return;
    }
    String videoUrl = args.getString(BUNDLE_VIDEO_URL);
    String altVideoUrl = args.getString(BUNDLE_ALT_VIDEO_URL);
    String webviewUrl = args.getString(BUNDLE_WEBVIEW_URL);
    Uri uri = Uri.parse(videoUrl);
    videoView.setMediaController(new VideoController(this, webviewUrl));
    videoView.setVideoURI(uri);
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        boolean tryAltVideo = !TextUtils.isEmpty(altVideoUrl);

        @Override
        public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
            if (tryAltVideo) {
                tryAltVideo = false;
                videoView.setVideoURI(Uri.parse(altVideoUrl));
                videoView.start();
                return true;
            }
            return false;
        }
    });
    videoView.setOnCompletionListener(mediaPlayer -> finish());
    videoView.requestFocus();
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) VideoController(com.byoutline.kickmaterial.views.VideoController) Uri(android.net.Uri) MediaPlayer(android.media.MediaPlayer)

Example 42 with MediaPlayer

use of android.media.MediaPlayer in project zxingfragmentlib by mitoyarzun.

the class BeepManager method buildMediaPlayer.

private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    //      mediaPlayer.release();
    return null;
//    }
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 43 with MediaPlayer

use of android.media.MediaPlayer in project Signal-Android by WhisperSystems.

the class IncomingRinger method createPlayer.

private MediaPlayer createPlayer() {
    try {
        MediaPlayer mediaPlayer = new MediaPlayer();
        Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
        mediaPlayer.setDataSource(context, ringtoneUri);
        mediaPlayer.setLooping(true);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
        return mediaPlayer;
    } catch (IOException e) {
        Log.e(TAG, "Failed to create player for incoming call ringer");
        return null;
    }
}
Also used : IOException(java.io.IOException) Uri(android.net.Uri) MediaPlayer(android.media.MediaPlayer)

Example 44 with MediaPlayer

use of android.media.MediaPlayer in project Lazy by l123456789jy.

the class RecorderControl method startPlaying.

/**
	 *
	 * @param Filename  Filename
	 * @param completion  completion
	 */
//
public void startPlaying(String Filename, OnCompletionListener completion) {
    if (!playState) {
        if (mPlayer == null) {
            mPlayer = new MediaPlayer();
        }
        try {
            mPlayer.setDataSource(Filename);
            mPlayer.prepare();
            playState = true;
            mPlayer.start();
            mPlayer.setOnCompletionListener(completion);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        if (mPlayer.isPlaying()) {
            mPlayer.stop();
            playState = false;
        //				startPlaying(Filename);
        } else {
            playState = false;
        }
    }
}
Also used : IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 45 with MediaPlayer

use of android.media.MediaPlayer in project Signal-Android by WhisperSystems.

the class AudioSlidePlayer method play.

public void play(final double progress) throws IOException {
    if (this.mediaPlayer != null)
        return;
    this.mediaPlayer = new MediaPlayer();
    this.audioAttachmentServer = new AttachmentServer(context, masterSecret, slide.asAttachment());
    audioAttachmentServer.start();
    mediaPlayer.setDataSource(context, audioAttachmentServer.getUri());
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.w(TAG, "onPrepared");
            synchronized (AudioSlidePlayer.this) {
                if (mediaPlayer == null)
                    return;
                if (progress > 0) {
                    mediaPlayer.seekTo((int) (mediaPlayer.getDuration() * progress));
                }
                mediaPlayer.start();
                setPlaying(AudioSlidePlayer.this);
            }
            notifyOnStart();
            progressEventHandler.sendEmptyMessage(0);
        }
    });
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            Log.w(TAG, "onComplete");
            synchronized (AudioSlidePlayer.this) {
                mediaPlayer = null;
                if (audioAttachmentServer != null) {
                    audioAttachmentServer.stop();
                    audioAttachmentServer = null;
                }
            }
            notifyOnStop();
            progressEventHandler.removeMessages(0);
        }
    });
    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.w(TAG, "MediaPlayer Error: " + what + " , " + extra);
            Toast.makeText(context, R.string.AudioSlidePlayer_error_playing_audio, Toast.LENGTH_SHORT).show();
            synchronized (AudioSlidePlayer.this) {
                mediaPlayer = null;
                if (audioAttachmentServer != null) {
                    audioAttachmentServer.stop();
                    audioAttachmentServer = null;
                }
            }
            notifyOnStop();
            progressEventHandler.removeMessages(0);
            return true;
        }
    });
    mediaPlayer.prepareAsync();
}
Also used : AttachmentServer(org.thoughtcrime.securesms.attachments.AttachmentServer) 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