如何知道Android中录音的长度
我使用以下代码来录制音频:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
startActivityForResult(Intent.createChooser(intent, "Select audio source"), CardList.ACTIVITY_RECDAUDIO);
当结果返回时,我执行以下操作:
Uri u = intent.getData();
String audioUri = u.getPath();
InputStream in = new BufferedInputStream(this.getContentResolver().openInputStream(u));
我想知道录制的时长(以秒为单位)。是否可以以某种方式查询这个?如果一切都失败了,我可以以编程方式播放剪辑并计时,但如果可能的话,我更喜欢更直接的方法。谢谢!
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));
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这对你来说是否足够快。但如果您不知道,您不必真正玩它。创建
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 callgetDuration()
.我通过使用输入流来执行此操作:InputStream 上的 is.available() 为我提供了长度。
I do this by using my input stream: is.available() on InputStream is gives me the length.