Click here to Skip to main content
Click here to Skip to main content

Tagged as

Android: Play Media File in the Assets Folder

, 17 Apr 2013
Rate this:
Please Sign up or sign in to vote.
Play a media file (wav, MP3, etc) 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();     
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Yildirim Kocdag
Architect
Turkey Turkey
Phd. Yildirim Kocdag is a Computer Engineer.
 
Programming Languages
Android, Objective-c, c#, vb.net, asp.net, javascript, TSQL.
 
Computer Science
DataMining, Compilers, Expert Systems, Digital Image Processing, AI and Extreme Programming.
 
ykocdag@yahoo.com
 
http://www.linkedin.com/profile/view?id=223886830
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 17 Apr 2013
Article Copyright 2013 by Yildirim Kocdag
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid