Question

I'm trying to play a simple live stream link on iOS. There's one view controller with a button with a play action defined as below.

- (IBAction)play:(id)sender {

    NSString *path = @"http://asish.flashmediacast.com:2135/live/International/playlist.m3u8";

    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
    [mp.view setFrame:[self.view bounds]];
    [mp prepareToPlay];
    [mp play];
}

Well nothing happens when the button's pressed. I've checked the link, it works fine. Where'm I going wrong?

I found a solution that tells you to create a MPMovieViewCOntroller

MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(moviePlaybackDidFinish:)
                                         name:MPMoviePlayerPlaybackDidFinishNotification
                                       object:nil];    

mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];

Question is how do I call this ViewCOntroller?

Was it helpful?

Solution

Look at this Link. The Problem is not with URL, its perfectly playing with MPMoviePlayerViewController.

-(IBAction)btnVideoClicked:(id)sender
{
    @try 
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
        GetVideos *obj_video = [arrVideos objectAtIndex:[sender tag]];
        MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:obj_video.VideoPath]];
        [moviePlayerViewController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
        [moviePlayerViewController.moviePlayer setShouldAutoplay:YES];
        [moviePlayerViewController.moviePlayer setFullscreen:NO animated:YES];
        [moviePlayerViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
        [moviePlayerViewController.moviePlayer setScalingMode:MPMovieScalingModeNone];
        [moviePlayerViewController.moviePlayer setUseApplicationAudioSession:NO];
        // Register to receive a notification when the movie has finished playing.  
        [[NSNotificationCenter defaultCenter] addObserver:self    selector:@selector(moviePlaybackStateDidChange:)      name:MPMoviePlayerPlaybackStateDidChangeNotification    object:moviePlayerViewController];
        // Register to receive a notification when the movie has finished playing.  
        [[NSNotificationCenter defaultCenter] addObserver:self     selector:@selector(moviePlayBackDidFinish:)    name:MPMoviePlayerPlaybackDidFinishNotification     object:moviePlayerViewController];
        [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
        moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
        [moviePlayerViewController release];
        [pool release];
    }
    @catch (NSException *exception) {
        // throws exception
    }
}

OTHER TIPS

Your first solutions is also correct. That way you get the flexibilty to set a frame for the video and place anywhere on the Screen. I guess you only missed to set the movieSourceType to MPMovieSourceTypeStreaming

- (IBAction)play:(id)sender {

    NSString *path = @"http://asish.flashmediacast.com:2135/live/International/playlist.m3u8";

    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
    mp.movieSourceType = MPMovieSourceTypeStreaming;
    [mp.view setFrame:[self.view bounds]];
    [self.view addSubview:mp.view];
    [mp prepareToPlay];
    [mp play];
}

Additionally, Capture the MoviePlayer State via similar code:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playbackFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:mp];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playbackChangeStateCallback:)
                                             name:MPMoviePlayerWillExitFullscreenNotification
                                           object:mp];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top