In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use MediaPlayer to adjust the playback speed", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use MediaPlayer to adjust the playback speed.
MediaPlayer.setPlaybackParams description
The playback speed is set in the PlaybackParams object, and then the object is passed into setPlaybackParams.
SetPlaybackParams is a native method.
If the MediaPlayer is not prepared (before prepared), calling this method does not change the state of the MediaPlayer.
After MediaPlayer succeeds in prepare, if the speed is set to 0, the pause method is called; if the speed is not set to 0, the start method is called.
Abnormal situation
If the MediaPlayer is not initialized or has been released, that is, it is in the Idle or End state, calling the setPlaybackParams method throws an IllegalStateException exception.
If the PlaybackParams passed in is not supported, an IllegalArgumentException exception is thrown.
If the setting speed is less than 0, a java.lang.IllegalArgumentException exception is thrown.
Example of MediaPlayer.setPlaybackParams method
Set the playback speed. Judge the current system version first.
Private boolean setPlaySpeed (float speed) {if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.M) {PlaybackParams params = mediaPlayer.getPlaybackParams (); params.setSpeed (speed); mediaPlayer.setPlaybackParams (params); return true;} return false;}
GetPlaybackParams can get the current PlaybackParams object of MediaPlayer.
You can also add try catch to this method and combine the returned Boolean value to determine whether the speed setting is successful or not.
Private boolean setPlaySpeed (float speed) {if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.M) {try {PlaybackParams params = mediaPlayer.getPlaybackParams (); params.setSpeed (speed); mediaPlayer.setPlaybackParams (params); return true;} catch (Exception e) {Log.e (TAG, "setPlaySpeed:", e); return false;}} return false;}
The speed value contained in PlaybackParams
When adjusting the MediaPlayer playback speed, we used the PlaybackParams object. This class is also used by AudioTrack.
PlaybackParams contains some properties during playback. For example, speed is the playback speed.
PlaybackParams.setSpeed (float speed)
Pass in the speed multiplier value. Marks that the speed is currently set.
Public PlaybackParams setSpeed (float speed) {mSpeed = speed; mSet | = SET_SPEED; return this;} PlaybackParams.getSpeed ()
Gets the set speed value. If the speed has not been set before, an IllegalStateException exception is thrown.
Public float getSpeed () {if ((mSet & SET_SPEED) = = 0) {throw new IllegalStateException ("speed not set");} return mSpeed;}
At this point, I believe you have a deeper understanding of "how to use MediaPlayer to adjust the playback speed". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.