Create a simple player for your iOS applications

This article is to detail how you might go about playing back a stream from within your app using Wowza as your streaming engine.   You will simply utilize the default MPMoviePlayerController object and just supply it with the appropriate Wowza url.

Create your view controller as follows:

ViewController.h

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

@interface ViewController : UIViewController
@property (strong, nonatomic) MPMoviePlayerController * player;
- (IBAction)playStream:(id)sender;
@end

ViewController.m

-(void)playStream:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://[wowza-ip]:1935/vod/_definst_/mp4:sample.mp4/playlist.m3u8″];
_player =  [[MPMoviePlayerController alloc]  initWithContentURL:url];   

    [[NSNotificationCenter defaultCenter] addObserver:self
              selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_player];

_player.controlStyle = MPMovieControlStyleDefault;
_player.shouldAutoplay = YES;

[self.view addSubview:_player.view];
[_player setFullscreen:YES animated:YES];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];

if ([player respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}

An attached demo application is attached for your convenience.  Tested against 7.1.  It includes the UI mappings from a basic button that initiates the player.  VideoPlayer


Comments are closed.