I have a table with audio data saved in BLOB format. I want to play the audio files but I have problem in calling the method from database.
This is my DatabaseAccess.java
public List<byte[]> getAudio(long i) {
List<byte[]> list = new ArrayList<>();
File file;
FileOutputStream fos;
byte[] byteaudio = null;
String selectAudio = "SELECT VocabAudio FROM Vocab WHERE VocabTopic =" + i;
Cursor c = database.rawQuery(selectAudio, null);
if(c.moveToFirst())
do{
byteaudio = c.getBlob(c.getColumnIndex("VocabAudio"));
try{
file = File.createTempFile("audio", "audio");
fos = new FileOutputStream(file);
fos.write(byteaudio);
fos.close();
}catch (IOException e){
e.printStackTrace();
}
}while(c.moveToNext());
return list;
}
This is my activity class where I want to call my getAudio() method. It says that it cannot find symbol variable file (from the Uri.fromFile(file)).
public void startSlides() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
Intent intent = getIntent();
long topicId = intent.getLongExtra("SelectedTopicId", 0);
databaseAccess.open();
List<byte[]> audio = databaseAccess.getAudio(topicId);
mp= MediaPlayer.create(Choice.this,Uri.fromFile(file));
i++;
mp.start();
databaseAccess.close();
if (j == vocab.size()+1) {
timer.cancel();
}
}
});
}
}, 0, 1000;
}
Anyone knows how should I call the getAudio() method? Thanks.