Tag Archives: MediaPlayer

How to encrypt and decrypt an audio file in Android?

By | May 8, 2018

Here is a simple example to encrypt and decrypt a audio file in Android. We will directly go to the implementation part. Demo Video You can check the demo video here. Download Library You can download the simple library from here. Aim Download an audio file from internet. Encrypt and save the encrypted file in Disk, so that… Read More »

Using Different Media Libraries in Android

By | February 5, 2017

Android provides two main API’s for playing sounds. SoundPool MediaPlayer SoundPool SoundPool can be used for small audio clips. It can repeat sounds and play several sounds simultaneously. The sound files played with SoundPool should not exceed 1 MB. SoundPool does load the file asynchronously. As of Android API8 it is possible to check if the loading is… Read More »

How to stream an audio in Android?

By | August 14, 2012

This is a simple example to how to stream an audio in android. Here is the java code for that. [java] package com.coderzheaven.pack; import android.app.Activity; import android.app.ProgressDialog; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.media.MediaPlayer.OnPreparedListener; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class StreamAudioDemo extends Activity implements OnClickListener, OnPreparedListener, OnErrorListener,… Read More »

How to check whether a video has completed playing in android?

By | January 6, 2012

Hello all… Today I will show you how to get notified when a video completes playing in android. PLease check this post for playing a video and the resources. First create a folder named “raw” inside the “res” folder and copy a video inside it. Now copy the xml from this link. For listening to the video completion… Read More »

How to record an audio in android and email it as attachment?

By | August 4, 2011

This example shows how to record an audio in android and save it in your path and send it as an email attachment. This example is taken from the developers website. Note : You should run this on the device otherwise it will not work. This example will open up an email client after recording and attach it… Read More »

How to use MediaPlayer in ANDROID? A simple example.

By | February 25, 2011

MediaPlayer class can be used to play Audio in ANDROID. See how to do this. [java] MediaPlayer mp = new MediaPlayer(); mp = MediaPlayer.create(MyClassName.this,songId); try { mp.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (Exception e) { Toast.makeText(Switch.this,e.getMessage() , Toast.LENGTH_SHORT).show(); } mp.start(); //Called when the song completes….. mp.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { } });… Read More »

Play all songs from your raw directory in ANDROID continuously.

By | February 10, 2011

In ANDROID all resource has a unique resource ID which we get by passing the song name to the function below playSong(). The function getAllResourceIDs() will convert this String which is the name of the song to the unique resource ID which can then be used to play the song. setOnCompletionListener() will be executed when the MediaPlayer completes… Read More »