How can I improve this simple streaming app?

Discussion in 'iOS Programming' started by Sobering, Aug 17, 2012.

  1. Sobering macrumors regular

    Aug 27, 2006
    Hey guys. I'm new to iOS development but I'm mostly comfortable with programming concepts in general, although I'm still new to software development as a whole.

    I've started creating an iPhone app that streams a radio station (which I have access to the raw mount point). I've got an app working with a Start/Stop button that plays the stream, but I'm a huge noob when it comes to this stuff.

    I've included my code in this post. I was just wondering how this could be improved. Right now when the button is pressed, it creates a new AVPlayer object and plays it, then when the button is pressed again it pauses it.

    Should I maybe make my own StreamObject class instead of doing everything in the streamButtonPressed method?

    #import "MyStreamerViewController.h"
    @interface MyStreamerViewController ()
    @property (strong, nonatomic) AVPlayer *player;
    @implementation MyStreamerViewController
    @synthesize player = _player;
    - (IBAction)streamButtonPressed:(UIButton *)sender
        UIButton *button = sender;
        NSString *buttonText = [button currentTitle];
        if ([buttonText isEqualToString:@"Start"]) {
            self.player = [AVPlayer playerWithURL:[NSURL URLWithString:@"YOUR STREAM URL"]];
            [self.player play];
            [button setTitle:@"Stop" forState:UIControlStateNormal];
            NSLog(@"The stream should be playing.");
        } else if ([buttonText isEqualToString:@"Stop"]) {
            [self.player pause];
            [button setTitle:@"Start" forState:UIControlStateNormal];
            NSLog(@"The stream should not be playing.");

Share This Page