Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sobering

macrumors regular
Original poster
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?

Code:
#import "MyStreamerViewController.h"

@interface MyStreamerViewController ()

@property (strong, nonatomic) AVPlayer *player;

@end

@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.");
    }
}

@end
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.