Play Audio with AVAudioPlayer with Swift 2.1

Today we will learn how to Pay Audio with AVAudioPlayer with Swift 2.1. The AVAudioPlayer class provides playback of audio files. The audio file can be played, paused and stopped. We can also display  the track title and playing time and also fast forward reverse and seek the file.

 

Start a new project, select SingleView application name it “BeatBox” save it. And start building your beat box.

Go to project targets – Build Phases – Link Binary with Libraries – Add “AVFoundation.framework” to your project.

Play Audio with AVAudioPlayer with Swift 2.1
Play Audio with AVAudioPlayer with Swift 2.1

Go to your ViewController.Swift file.

also

The AVAudioPlayer can can play almost every format. Now we will drag drop an audio file in our project.

In you view did load write the below code.

if you want to update time every single second then

Create the function for time.

There are some other properties of audio player like.

Go ahead and build your own music player.

Today we learn how to Play Audio with AVAudioPlayer with Swift 2.1. Nest time there will be something more exciting. Or you can ask for any tutorial. Till then Happy Coding 🙂

4 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.