Shoucast Streaming in iOS (Objective-C)

In this post I’m going to cover how to build an iOS app that streams songs from Shoutcast server.

  1.  Open your XCode and Create a new project, select Single View Application and click in Next

Captura de Tela 2015-12-01 às 22.18.42

2. Name your app for Shoutcast, and then select Objective-C, and click in Next

Captura de Tela 2015-12-01 às 22.18.58

3. Create a button and name it play. This button will start the streaming

Captura de Tela 2015-12-01 às 22.26.59

4. Go to View->Assistent Editor->Show Assitent Editor

Captura de Tela 2015-12-01 às 22.27.39

5. Create an action called playMusic like the picture below:

Captura de Tela 2015-12-01 às 22.32.23

6. Open your ViewCotroller.h to create a property called myStreaming(you should create this property as strong, if you don’t do this the streaming will stop after 2 seconds)

Captura de Tela 2015-12-01 às 22.35.41

7. Now go to your ViewController.m and inside the method playMusic you should call the property you defined in your h file.

The First thing you need to have is the streaming URL (shoucast’s urls should have the address and the port), then your need to init the streaming property, after that you should define the source type, in our case is streaming, after all you just need to set shouldAutoPlay to NO and prepare to play the streaming and finally play.

– (IBAction)playMusic:(id)sender {    

 NSURL *myUrl = [NSURL  URLWithString:@”http://colinawebradio.com.br:9986″];

 self.myStreaming = [[MPMoviePlayerController alloc] initWithContentURL:myUrl];

  self.myStreaming.movieSourceType =         MPMovieSourceTypeStreaming;

   self.myStreaming.shouldAutoplay = NO;

   [self.myStreaming prepareToPlay];

   [self.myStreaming play];

}

After all, run your app and listen to the radio 🙂

That’s all, thanks :).

If you have any questions, feel free to ask.

See you guys next time!

Advertisements