Click here to Skip to main content
Full site     10M members (33.5K online)    

Android: Play Media File in the Assets Folder

Introduction

Play a media file (wav, MP3, etc) in the Assets folder.

Using the code

You can write an application using the code that plays a media file which is stored in your Assets folder.

Play a Media File in Assets Folder

public void Play(String fileName)
{
    AssetFileDescriptor descriptor = _context.getAssets().openFd(fileName);
    long start = descriptor.getStartOffset();
    long end = descriptor.getLength();
    MediaPlayer mediaPlayer=new MediaPlayer();
    mediaPlayer.setDataSource(descriptor.getFileDescriptor(), start, end);
    mediaPlayer.prepare();
    mediaPlayer.start();     
}
 
You must Sign In to use this message board.
Search 
Per page   
-- There are no messages in this forum --

Last Updated 17 Apr 2013 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013