Stream online music in Objective c .

Learn how to stream audio files online , similar to the one you will see in Saavn or SoundCloud. Online streaming is very popular these days as it saves a lot of data of your device(iPhones and iPads).


In this tutorial i will tell you about streaming audio over internet without downloading the content .

Step 1: 

Open Xcode and create a new project.


Step 2: 

Add AVFoundation Framework to your project.

For adding framework go to your Project >>> Selects Targets  >>> Go to Build Settings  >>> Click on  + button and add AVFoundation Framework to your project.


Step 3:

Import the AVFoundation framework in your ViewController.m file by :

#import <AVFoundation/AVFoundation.h>


Step 4:

Create a UIButton so that we can play or pause the audio .

  1. Go to storyboard and drag the UIButton .
  2. Make its connection with the ViewController.

Step 5:

In ViewController.m add global elements by :




Step 6:

Add the following code to initialize AVPlayer and add online streaming in it.





Add url of any audio file you want to play.





Step 7:


Last step in this tutorial is to Add Transport Security Settings in your application.

If you are using Xcode 7 , then add the Add Transport Security Settings in info.plist
and under Add Transport Security Settings  >> make Allow Arbitrary Loads to YES as shown below:



Add Transport Security Settings







Thats all about the Live streaming in iOS applications .



Thank you  :)

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. the url link only works once how can i get it to play unlimited times

    ReplyDelete
    Replies
    1. Set the Property numberOfLoops to -1 and it would go into infinite loop.

      Delete
  3. Hello sir,
    hwo we implement seek bar.

    ReplyDelete
  4. can you upload about coredata in objective c

    ReplyDelete

Post a Comment

Popular Posts