首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Parse中检索音频

从Parse中检索音频
EN

Stack Overflow用户
提问于 2015-07-15 08:44:16
回答 1查看 432关注 0票数 0

我有一个应用程序,录制音频,并保存在服务器上的解析。我正在试着找回它来播放录制的音频。

服务器介于两者之间,因为应用程序将音频从一个用户发送到另一个用户。我只是有点困惑于ParseFile是如何工作的,以及播放它的最好方法是什么。

现在我正在查询这个对象,获取它的音频属性作为ParseFile,获取url,然后从服务器流传输该url。

代码语言:javascript
复制
// 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

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-09-15 23:17:37

这里是关于kurtis92的问题:How to retrieve and play mp3 files from Parse.com

代码语言:javascript
复制
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();
                      }
                  }
             }
         });
      }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31419680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档