Android Tempo/播放速度更改 [英] Android Tempo/playback speed change

查看:296
本文介绍了Android Tempo/播放速度更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Android应用,该应用需要实时更改播放速率/速度.我在互联网上进行了搜索,看到了许多解决方案,包括 适用于Android的OpenSL ES教程 如何使用ffmpeg更改音频速度和音高个性? /a>

I am creating an Android app which requires the real time change of playback rate/speed. I have searched all over the internet and have seen many solutions including Tutorials for OpenSL ES for Android How to change audio tempo and pitch individuality using ffmpeg?

由于我对开发和android相对较新,所以其中有些根本不在我的学习范围之内.

As i am relatively new to development and android some of these are simply out of my leauge.

其中许多示例都谈到了Soundpool,但是此api不适用于大文件.

Many of these examples talk about Soundpool but this api does not work with large files.

在查看了API和类之后,我发现了方法setPlaybackRate(int sampleRateInHz) 在AudioTrack类下. http://developer.android.com/reference/android /media/AudioTrack.html#setPlaybackRate(int)

After looking through API's and classes i found the method setPlaybackRate(int sampleRateInHz) under the AudioTrack class. http://developer.android.com/reference/android/media/AudioTrack.html#setPlaybackRate(int)

但是,在所有这些在线示例中,没有一个提到这一点.我是否缺少某些东西并且可以使用?

However in all these examples online none of them mention this. Am i missing something and can it be used?

非常感谢您的帮助

推荐答案

API 23 开始,MediaPlayer可以使用

Beginning API 23, MediaPlayer can set playback speed using this method.

MediaPlayer类

Class MediaPlayer

public void setPlaybackParams (PlaybackParams params)已在API中添加 23级

public void setPlaybackParams (PlaybackParams params) Added in API level 23

使用PlaybackParams设置播放速率.参数参数 PlaybackParams:播放参数.如果抛出IllegalStateException 内部播放器引擎尚未初始化. 如果不支持params,则抛出IllegalArgumentException.

Sets playback rate using PlaybackParams. Parameters params PlaybackParams: the playback params. Throws IllegalStateException if the internal player engine has not been initialized. IllegalArgumentException if params is not supported.

示例代码:

MediaPlayer mp = ...; //Whatever
float speed = 0.75f;     
mp.setPlaybackParams(mp.getPlaybackParams().setSpeed(speed));

这篇关于Android Tempo/播放速度更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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