Search in sources :

Example 1 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 2 with MediaPlayer

use of android.media.MediaPlayer in project android-app by eoecn.

the class CaptureActivity method initBeepSound.

/**
     * 扫描正确后的震动声音,如果感觉apk大了,可以删除
     */
private void initBeepSound() {
    if (playBeep && mediaPlayer == null) {
        // The volume on STREAM_SYSTEM is not adjustable, and users found it
        // too loud,
        // so we now play on the music stream.
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnCompletionListener(beepListener);
        AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
            file.close();
            mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
            mediaPlayer.prepare();
        } catch (IOException e) {
            mediaPlayer = null;
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 3 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.

the class HTML5VideoView method init.

// Every time we start a new Video, we create a VideoView and a MediaPlayer
public void init(int videoLayerId, int position, boolean skipPrepare) {
    if (mPlayer == null) {
        mPlayer = new MediaPlayer();
        mCurrentState = STATE_INITIALIZED;
    }
    mSkipPrepare = skipPrepare;
    // If we want to skip the prepare, then we keep the state.
    if (!mSkipPrepare) {
        mCurrentState = STATE_INITIALIZED;
    }
    mProxy = null;
    mVideoLayerId = videoLayerId;
    mSaveSeekTime = position;
    mTimer = null;
    mPauseDuringPreparing = false;
}
Also used : MediaPlayer(android.media.MediaPlayer)

Example 4 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.

the class MediaSource method setupMediaPlayer.

/** Creates a media player, sets it up, and calls prepare */
private synchronized boolean setupMediaPlayer(boolean useUrl) {
    mPrepared = false;
    mGotSize = false;
    mPlaying = false;
    mPaused = false;
    mCompleted = false;
    mNewFrameAvailable = false;
    if (mLogVerbose)
        Log.v(TAG, "Setting up playback.");
    if (mMediaPlayer != null) {
        // Clean up existing media players
        if (mLogVerbose)
            Log.v(TAG, "Resetting existing MediaPlayer.");
        mMediaPlayer.reset();
    } else {
        // Create new media player
        if (mLogVerbose)
            Log.v(TAG, "Creating new MediaPlayer.");
        mMediaPlayer = new MediaPlayer();
    }
    if (mMediaPlayer == null) {
        throw new RuntimeException("Unable to create a MediaPlayer!");
    }
    // Set up data sources, etc
    try {
        if (useUrl) {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
            if (mContext == null) {
                mMediaPlayer.setDataSource(mSourceUrl);
            } else {
                mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
            }
        } else {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
            mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());
        }
    } catch (IOException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    } catch (IllegalArgumentException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    }
    mMediaPlayer.setLooping(mLooping);
    mMediaPlayer.setVolume(mVolume, mVolume);
    // Bind it to our media frame
    Surface surface = new Surface(mSurfaceTexture);
    mMediaPlayer.setSurface(surface);
    surface.release();
    // Connect Media Player to callbacks
    mMediaPlayer.setOnVideoSizeChangedListener(onVideoSizeChangedListener);
    mMediaPlayer.setOnPreparedListener(onPreparedListener);
    mMediaPlayer.setOnCompletionListener(onCompletionListener);
    // Connect SurfaceTexture to callback
    mSurfaceTexture.setOnFrameAvailableListener(onMediaFrameAvailableListener);
    if (mLogVerbose)
        Log.v(TAG, "Preparing MediaPlayer.");
    mMediaPlayer.prepareAsync();
    return true;
}
Also used : IOException(java.io.IOException) IllegalArgumentException(java.lang.IllegalArgumentException) MediaPlayer(android.media.MediaPlayer) Surface(android.view.Surface)

Example 5 with MediaPlayer

use of android.media.MediaPlayer in project android_frameworks_base by ParanoidAndroid.

the class VideoDumpView method onResume.

@Override
public void onResume() {
    Log.d(TAG, "onResume");
    mMediaPlayer = new MediaPlayer();
    try {
        mMediaPlayer.setDataSource(VideoDumpConfig.VIDEO_URI);
        class RGBFilter implements FilenameFilter {

            public boolean accept(File dir, String name) {
                return (name.endsWith(VideoDumpConfig.IMAGE_SUFFIX));
            }
        }
        File dump_dir = new File(VideoDumpConfig.ROOT_DIR);
        File[] dump_files = dump_dir.listFiles(new RGBFilter());
        for (File dump_file : dump_files) {
            dump_file.delete();
        }
        File image_list = new File(VideoDumpConfig.ROOT_DIR + VideoDumpConfig.IMAGES_LIST);
        image_list.delete();
        mImageListWriter = new BufferedWriter(new FileWriter(image_list));
    } catch (java.io.IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    queueEvent(new Runnable() {

        public void run() {
            mRenderer.setMediaPlayer(mMediaPlayer);
            mRenderer.setImageListWriter(mImageListWriter);
        }
    });
    super.onResume();
}
Also used : FilenameFilter(java.io.FilenameFilter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) MediaPlayer(android.media.MediaPlayer) BufferedWriter(java.io.BufferedWriter)

Aggregations

MediaPlayer (android.media.MediaPlayer)365 IOException (java.io.IOException)177 LargeTest (android.test.suitebuilder.annotation.LargeTest)60 AudioEffect (android.media.audiofx.AudioEffect)54 AudioManager (android.media.AudioManager)49 AssetFileDescriptor (android.content.res.AssetFileDescriptor)27 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 VideoView (android.widget.VideoView)11 File (java.io.File)11 Intent (android.content.Intent)8 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)7 Surface (android.view.Surface)7 MediaController (android.widget.MediaController)7 MediaFormat (android.media.MediaFormat)6 UtteranceProgressDispatcher (android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher)6 View (android.view.View)6