B K
B K

Reputation: 1564

How to Stream video to iPad from a server?

I am streaming a video into my iPad app from a server. I am using the following code:

    NSURL *videoURL = [NSURL URLWithString:@"http://10.1.0.251/blah/videos/test.mp4"]; 
MPMoviePlayerViewController* playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
playerController.moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;

This gives me no control over the frame for the video and also the player quits after playing the video once? How can i control the frame and allow "replays"?

The following code allows me the above functionality on a iPhone and also on iPad(local videos only not streaming)

NSURL *url = [NSURL URLWithString:strVideo];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.view.frame = CGRectMake(50, 50, 480, 320);
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
    moviePlayer.shouldAutoplay = YES;
    moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
    [self.view addSubview:moviePlayer.view];
           [moviePlayer play];

How do I achieve the same for iPad?

Upvotes: 2

Views: 2709

Answers (2)

hujj
hujj

Reputation: 11

Though its data comes from the net, its data type is file. So, modify the below code:

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

Upvotes: 1

B K
B K

Reputation: 1564

Ok, the above customization cannot be achieved in an ipad. The MPMoviePlayerController or the MPMoviePlayerViewController do not allow that.

Those who need such custom close buttons, the workaround that I am using would be to play the video via a UIWebView and have such close buttons over it. Not elegant but does the job.

EDIT: If you need to do the same for videos playing locally then it can be achieved via MPMoviePlayerController.

Upvotes: 0

Related Questions