Using Audio-Video Files Tutorial For Android

Audio Files

Here is the source code how to use(via app & online uri) the audio file in android

try {
   AudioManager audioManager;
   MediaPlayer mediaPlayer;
   audioManager = (AudioManager) 
                  this.getSystemService(this.AUDIO_SERVICE);
   mediaPlayer=MediaPlayer
                   .create(this, Uri.parse("some online url"));      
   mediaPlayer=MediaPlayer
                   .create(this, R.raw.alarm1);
   int streamVolume=audioManager
                   .getStreamVolume(AudioManager.STREAM_MUSIC);
   mediaPlayer.setVolume(streamVolume, streamVolume);
   mediaPlayer.start();
   Thread.sleep(3000);
   mediaPlayer.stop();
} catch (Exception e) {	}

Video Files

Here is the source code how to use(via online uri) the video file in android

private VideoView mVideoView;
mVideoView = (VideoView) findViewById(R.id.surface_view);
try {
    final String path = mPath.getText().toString();
    if (path == null || path.length() == 0) {
        Toast.makeText(VideoViewDemo.this, "File URL/path is empty",
        Toast.LENGTH_LONG).show();
    } else {
        if (path.equals(current) && mVideoView != null) {
	     mVideoView.start();
	     mVideoView.requestFocus();
	     return;
         }
    current = path;
    //mVideoView.setVideoPath(R.raw.vid);
    mVideoView.setVideoPath(getDataSource(path));
    mVideoView.start();
    mVideoView.requestFocus();
    }
} catch (Exception e) {}

Run the code on mobile.

here is the complete source code.

Advertisements
This entry was posted in Android, Tutorials and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s