如何知道Android的音频录音的长度 [英] How to know the length of an audio recording in Android

查看:858
本文介绍了如何知道Android的音频录音的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code录制音频:

I am using the following code to record audio:

  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  intent.setType("audio/*");
  startActivityForResult(Intent.createChooser(intent, "Select audio source"), CardList.ACTIVITY_RECDAUDIO);

当结果回来我做到以下几点:

When the result comes back I do the following:

  Uri u = intent.getData();
  String audioUri = u.getPath();
  InputStream in = new BufferedInputStream(this.getContentResolver().openInputStream(u));

我想知道的记录以秒为单位的时间。是否有可能以某种方式查询呢?如果一切都失败,我可以编程播放的剪辑和时间,但我想preFER更直接的方法,如果可能的话。谢谢!

I would like to know how long the recording is in seconds. Is it possible to query this somehow? If all else fails I can play the clip programatically and time it, but I would prefer a more direct method if possible. Thanks!

推荐答案

我不知道这是不是对你不够快。但如果你不知道 - 你没有真正发挥它。这足以创建的MediaPlayer 实例,并设置文件的路径和呼叫 getDuration()

I don't know if this is fast enough for you. But in case you don't know - you don't have to actually play it. It is enough to create MediaPlayer instance and set the path of the file and the call getDuration().

MediaPlayer mp = MediaPlayer.create(yourActivity, Uri.parse(path));
int duration = mp.getDuration();

这篇关于如何知道Android的音频录音的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆