我有一个应用程序,录制音频,并保存在服务器上的解析。我正在试着找回它来播放录制的音频。
服务器介于两者之间,因为应用程序将音频从一个用户发送到另一个用户。我只是有点困惑于ParseFile是如何工作的,以及播放它的最好方法是什么。
现在我正在查询这个对象,获取它的音频属性作为ParseFile,获取url,然后从服务器流传输该url。
// result is the object I got from the query, it holds the ParseFile
ParseFile audioFile = result.getAudioFile();
String audioFileURL = audioFile.getUrl();
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);
try {
mMediaPlayer.setDataSource(audioFileURL);
mMediaPlayer.prepare();
mMediaPlayer.start();
}catch (Exception e){}我认为这不是最好的方法,最好将它保存在本地。我知道你可以使用getDataInBackground,但我只是搞不懂它对实际的ParseFile有什么影响。一旦我在后台获得了字节数组形式的数据,那么存储它的最好方法是什么,这样我就不必每次都调用getDataInBackground了?我是否应该使用从getDataInBackground中获得的数据生成的新ParseFile来覆盖该get
谢谢。
发布于 2015-09-15 23:17:37
这里是关于kurtis92的问题:How to retrieve and play mp3 files from Parse.com
MediaPlayer mediaPlayer;
public void play(View view) { // function onClick of a button
mediaPlayer = new MediaPlayer();
ParseQuery<ParseObject> query = ParseQuery.getQuery("sveglia"); // sveglia is the name of the Class
query.getInBackground("hQHeNCqccH", new GetCallback<ParseObject>() { //hQHeNCqccH is the ID of the file audio u wanna stream
public void done(ParseObject recording, com.parse.ParseException e) {
if (e != null) {
//do nothing
} else {
ParseFile audioFile = recording.getParseFile("audio"); // audio is the column of the file audio
String audioFileURL = audioFile.getUrl();
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(audioFileURL);
mediaPlayer.prepare();
mediaPlayer.start();
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
}https://stackoverflow.com/questions/31419680
复制相似问题