package com.demo;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.AvoidXfermode;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.view.SurfaceHolder;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.MediaController.MediaPlayerControl;
@SuppressWarnings("unused")
public class AudioPlayer
{
String fileName;
Context contex;
Uri path;
MediaPlayer mp;
public AudioPlayer( String name, Context context)
{
fileName=name;
contex=context;
AssetManager am = contex.getAssets();
path = Uri.fromFile(new File("assets/"));
playAudio();
}
public void playAudio()
{
mp = new MediaPlayer();
try {
AssetFileDescriptor descriptor = contex.getAssets().openFd(fileName);
mp.setDataSource( descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength() );
descriptor.close();
mp.prepare();
mp.start();
mp.setVolume(5, 5);
}
catch (IllegalArgumentException e)
{
e.printStackTrace();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void stop()
{
mp.stop();
}
}
No comments:
Post a Comment