Software7

Personal Developer Notebook

Developing a HTTP Live Streaming App for iOS

 

HTTP Live Streaming (HLS) allows you to send audio and video without special server software to iOS-based devices. It supports multiple streams at different bit rates allowing the client to choose the one that fits the current bandwith the best.

A very simple video player app for iOS using HTTP live streaming can be created in a few minutes, see the following screencast.

The header file:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h> 

@interface ViewController : UIViewController

@property (nonatomic,strong) MPMoviePlayerController *player;

@end

The implementation file:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *stream = [NSURL URLWithString:@"http://www.software7.com/wp-content/uploads/2015/01/videoPlayer/prog_index.m3u8"];
    self.player = [[MPMoviePlayerController alloc] initWithContentURL:stream];
    
    UIView *playerView = self.player.view;
    
    [playerView setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [self.view addSubview:playerView];
    
    [self.view addConstraints:[NSLayoutConstraint
                               constraintsWithVisualFormat:@"H:|-0-[playerView]-0-|"
                               options:NSLayoutFormatDirectionLeadingToTrailing
                               metrics:nil
                               views:NSDictionaryOfVariableBindings(playerView)]];
    
    [self.view addConstraints:[NSLayoutConstraint
                               constraintsWithVisualFormat:@"V:|-0-[playerView]-0-|"
                               options:NSLayoutFormatDirectionLeadingToTrailing
                               metrics:nil
                               views:NSDictionaryOfVariableBindings(playerView)]];
    [self.player play];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end