Search in sources :

Example 6 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project ABPlayer by winkstu.

the class MediaPlayerDemo_Audio method createMediaPlayer.

public MediaPlayer createMediaPlayer(Context context, int resid) {
    try {
        AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid);
        MediaPlayer mp = new MediaPlayer(context);
        mp.setDataSource(afd.getFileDescriptor());
        afd.close();
        mp.prepare();
        return mp;
    } catch (IOException ex) {
        Log.d(TAG, "create failed:", ex);
    // fall through
    } catch (IllegalArgumentException ex) {
        Log.d(TAG, "create failed:", ex);
    // fall through
    } catch (SecurityException ex) {
        Log.d(TAG, "create failed:", ex);
    // fall through
    }
    return null;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 7 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project ABPlayer by winkstu.

the class MediaPlayerDemo_Video method playVideo.

private void playVideo(Integer Media) {
    doCleanUp();
    try {
        switch(Media) {
            case LOCAL_VIDEO:
                /*
				 * TODO: Set the path variable to a local media file path.
				 */
                path = "/storage/sdcard0/BaiduNetdisk/�ҵ���Դ/5/33.rmvb";
                if (path == "") {
                    // Tell the user to provide a media file URL.
                    Toast.makeText(MediaPlayerDemo_Video.this, "Please edit MediaPlayerDemo_Video Activity, " + "and set the path variable to your media file path." + " Your media file must be stored on sdcard.", Toast.LENGTH_LONG).show();
                    return;
                }
                break;
            case STREAM_VIDEO:
                /*
				 * TODO: Set path variable to progressive streamable mp4 or
				 * 3gpp format URL. Http protocol should be used.
				 * Mediaplayer can only play "progressive streamable
				 * contents" which basically means: 1. the movie atom has to
				 * precede all the media data atoms. 2. The clip has to be
				 * reasonably interleaved.
				 * 
				 */
                // path = "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
                path = "http://us-chicago.acgvideo.com/67.159.54.58/1/45/3262388-1.flv?expires=1430688900&ssig=VuoBrnO8dUUG4jyJe3FF2Q&o=401361084&rate=0";
                if (path == "") {
                    // Tell the user to provide a media file URL.
                    Toast.makeText(MediaPlayerDemo_Video.this, "Please edit MediaPlayerDemo_Video Activity," + " and set the path variable to your media file URL.", Toast.LENGTH_LONG).show();
                    return;
                }
                break;
        }
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer(this);
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
Also used : MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 8 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project VitamioBundle by yixia.

the class VideoViewDemo method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    mEditText = (EditText) findViewById(R.id.url);
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
			 * Alternatively,for streaming media you can use
			 * mVideoView.setVideoURI(Uri.parse(URLstring));
			 */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }
}
Also used : MediaController(io.vov.vitamio.widget.MediaController) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 9 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project VitamioBundle by yixia.

the class MediaPlayerDemo_Audio method playAudio.

private void playAudio(Integer media) {
    try {
        switch(media) {
            case LOCAL_AUDIO:
                /**
                 * TODO: Set the path variable to a local audio file path.
                 */
                path = "";
                if (path == "") {
                    // Tell the user to provide an audio file URL.
                    Toast.makeText(MediaPlayerDemo_Audio.this, "Please edit MediaPlayer_Audio Activity, " + "and set the path variable to your audio file path." + " Your audio file must be stored on sdcard.", Toast.LENGTH_LONG).show();
                    return;
                }
                mMediaPlayer = new MediaPlayer(this);
                mMediaPlayer.setDataSource(path);
                mMediaPlayer.prepare();
                mMediaPlayer.start();
                break;
            case RESOURCES_AUDIO:
                /**
                 * TODO: Upload a audio file to res/raw folder and provide its resid in
                 * MediaPlayer.create() method.
                 */
                // Bug need fixed
                mMediaPlayer = createMediaPlayer(this, R.raw.test_cbr);
                mMediaPlayer.start();
        }
        tx.setText("Playing audio...");
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) MediaPlayer(io.vov.vitamio.MediaPlayer)

Example 10 with MediaPlayer

use of io.vov.vitamio.MediaPlayer in project VitamioBundle by yixia.

the class VideoViewBuffer method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videobuffer);
    mVideoView = (VideoView) findViewById(R.id.buffer);
    pb = (ProgressBar) findViewById(R.id.probar);
    downloadRateView = (TextView) findViewById(R.id.download_rate);
    loadRateView = (TextView) findViewById(R.id.load_rate);
    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewBuffer.this, "Please edit VideoBuffer Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
       * Alternatively,for streaming media you can use
       * mVideoView.setVideoURI(Uri.parse(URLstring));
       */
        uri = Uri.parse(path);
        mVideoView.setVideoURI(uri);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
        mVideoView.setOnInfoListener(this);
        mVideoView.setOnBufferingUpdateListener(this);
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                mediaPlayer.setPlaybackSpeed(1.0f);
            }
        });
    }
}
Also used : MediaController(io.vov.vitamio.widget.MediaController) MediaPlayer(io.vov.vitamio.MediaPlayer)

Aggregations

MediaPlayer (io.vov.vitamio.MediaPlayer)14 IOException (java.io.IOException)7 Intent (android.content.Intent)2 AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 MediaController (io.vov.vitamio.widget.MediaController)2 SuppressLint (android.annotation.SuppressLint)1 Surface (android.view.Surface)1 OnHWRenderFailedListener (io.vov.vitamio.MediaPlayer.OnHWRenderFailedListener)1 OnTimedTextListener (io.vov.vitamio.MediaPlayer.OnTimedTextListener)1