iOS 9 audio app play audio control playback speed iOS 9 audio control playback speed
IOS9 audio files are played at a certain speed during playback. This speed can be changed to enable fast playback and slow playback of iOS9 audio files. Changes to achieve iOS9 playback speed need to be implemented using the rate attribute in the Avaudioplayer class. Its grammatical form is as follows:
Where the value set by this property is a floating-point type, ranging from 0.5 to 2.0. If the value of this property is set to 1.0 for normal playback, it is also the default value. 2.0 means playing at the fastest speed and 0.5 means playing at the slowest speed.
Note: If the developer wants iOS 9 audio to achieve a change in playback speed, the Enablerate property must be set to whether the function of this property allows the playback speed to be changed. Its grammatical form is as follows:
Where the value of this property is set to a Boolean type. A value of TRUE indicates that the playback speed is allowed to change, and conversely, the playback speed is not changed.
Example 2-6 below will be based on the first iOS 9 audio instance, allowing the user to control the playback speed of the audio file. The following steps are described:
(1 ) Associates the Rate Text field text box in the main view with the socket variable Ratetextfield.
(2 ) Associates the Rate Text field text box in the main view with the action setrate.
(3 Right-click the Rate Text field text box in the main view, and the Rate Text Field dialog box pops up, as shown in 2.27.
(4 Select the Do End on exit option under sent events to associate this option with the view controller in the dock, as shown in 2.28.
(5) After the Do End on exit option is associated with a view controller in the dock, the currently declared method pops up, as shown in 2.29.
Figure 2.28 IOS 9 Audio Associate
(6 Select the Setrate: Method at which the did End on exit is associated with the Setrate: method, as shown in 2.30.
Figure 2.29 IOS 9 Audio Pop-up Method dialog block diagram 2.30 IOS 9 Audio the effect after the association
(7 Open the Viewcontroller.swift file, write code, and achieve playback speed control. The code is as follows:
- @IBAction func setrate (sender:anyobject) {
- Ratetextfield.resignfirstresponder ()// Turn off the keyboard
- Determine if the audio file has not started playing
- if (audioeffect!. Playing==false && audioeffect? CurrentTime = = 0.0) {
- Did not start playback
- audioeffect?. Enablerate=true //allow change of playback speed
- Let Ratevalue=nsstring (string:ratetextfield.text!). Floatvalue
- audioeffect?. Rate=ratevalue //Set playback speed
- Hidemoresettingsview ()
- }else{
- Start playback
- Let Alertcontroller = Uialertcontroller (title: "Hint", Message: "Music on has been played, invalid settings", Preferredstyle: Uialertcontrollerstyle.alert)
- Turn off more setup items
- Let action = uialertaction (title: " known", Style:UIAlertActionStyle.Default) {
- (action:uialertaction!) -Void in
- Self.hidemoresettingsview ()
- }
- Alertcontroller.addaction (Action)
- Self.presentviewcontroller (Alertcontroller, Animated:true, Completion:nil)
- }
- }
At this point, run the program, tap more buttons in the emulator interface that appears, pop up more settings, enter a number in the text box corresponding to the playback speed, press RETURN, and exit more settings. Tap the play button and the audio file will play. The speed at which the audio file plays is related to the number entered by the user.
Note: If the developer taps more buttons after a period of time in an iOS 9 audio file and enters the playback speed in more settings that pops up, the speed entered is not valid and it cannot control the playback speed of the audio file, so when the return key is pressed, it pops up " IOS9 Music has been played, set invalid "Warning view, shown in 2.31.
Figure 2.31 IOS 9 Audio Warning View
This article is selected from:IOS 9 Audio Application Development Basic Tutorial University PA Internal information, reproduced please indicate the source, respect the technology respect the IT person!
IOS 9 Audio App play audio control playback speed