I am new bee to android. I have some about 120 audio files, which I want to store in database and then on different button clicks the audio files will retrieve which I want to play. I don't know how to do this. I have searched several links but unable to find help. I have little knowledge of SQLite database, any help will be appreciated.
here is my code , I have now only one audio file saved in assets folder. If this can help.
import java.io.IOException;
import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyButtonsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final MediaPlayer mp = new MediaPlayer();
Button c = (Button)findViewById(R.id.btnstop);
Button b = (Button)findViewById(R.id.btnplay);
c.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(mp.isPlaying())
{
mp.stop();
}
}
});
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
mp.reset();
AssetFileDescriptor afd;
afd = getAssets().openFd("audio/001s-ff.mp3");
mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
mp.prepare();
mp.start();
}
catch (IllegalStateException e)
{
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
One thing more , where should I save my 100+ audio files? In assets folder manually or in database? which way will be more light in size?
Aucun commentaire:
Enregistrer un commentaire