Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Streaming video from server....Not easy..help would be appreciated!

Dear Developers,


It has been a long time since I have posted on this community - its nice to see some familiar avatars still here.


I have been developing an iphone/ipad app for cancer patients that requires streaming of video footage from a server. The app is sturctured in a simple tableview with images of a range of videos. The user selects these tableview cells and the video should then stream.


I hoped to use material saved on a private youTube account - but getting a seamless stream from the Tableview selection hasnt been easy. It seems that youTube clips must be loaded into a uiWebview and then selected. This feels clumsy.


I have subsequently opted to stream from an alternative server with .mov files. The code I am using is as follows:



NSString *videoURLString = @"https://www.dropbox.com/s/7wmltu14ti91qm9/IMG_0024.MOV";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
[moviePlayer prepareToPlay]; 
[moviePlayer play];
[self.view addSubview:moviePlayer.view];


When I select call this code the movieplayer opens, but the video will not load. I recieve an error warning in the console containing :


CGcontextsaveGState: invalid context 0x0

CGContextClipToRect: Invalid context 0x0

CGContextTranslateCTM: invalid context 0x0

CGContextDrawShading: invalid context 0x0

CGContextRestoreGSState: invalid context 0x0.



What must I do to get this code working ?


I would be very grateful for your help on this. I am also keen to learn if anyone knows of other source code that would provide a cleaner experience of youtube video streaming.

with thanks.


James

Posted on Jul 25, 2013 1:20 PM

Reply
Question marked as Best reply

Posted on Jul 25, 2013 1:27 PM

You may use this:


NSString *videoFilepath = @"https://www.dropbox.com/s/7wmltu14ti91qm9/IMG_0024.MOV";

NSURL *videoURL = [NSURL URLWithString:videoFilepath];

MPMoviePlayerViewController *movie = [[MPMoviePlayerViewControlleralloc] initWithContentURL:videoURL];

[[NSNotificationCenterdefaultCenter] addObserver:self

selector:@selector(playbackFinishedCallback:)

name:MPMoviePlayerPlaybackDidFinishNotification

object:movie];

[selfpresentMoviePlayerViewControllerAnimated:movie];


then


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

NSError *error = [[notification userInfo] objectForKey:@"error"];

if (error) {

NSLog(@"Did finish with error: %@", error);

}

}


add the MediaPlayer.framework to your project &

add to your .h

#import <MediaPlayer/MediaPlayer.h>



Hope this helps

6 replies
Question marked as Best reply

Jul 25, 2013 1:27 PM in response to james_coleman01

You may use this:


NSString *videoFilepath = @"https://www.dropbox.com/s/7wmltu14ti91qm9/IMG_0024.MOV";

NSURL *videoURL = [NSURL URLWithString:videoFilepath];

MPMoviePlayerViewController *movie = [[MPMoviePlayerViewControlleralloc] initWithContentURL:videoURL];

[[NSNotificationCenterdefaultCenter] addObserver:self

selector:@selector(playbackFinishedCallback:)

name:MPMoviePlayerPlaybackDidFinishNotification

object:movie];

[selfpresentMoviePlayerViewControllerAnimated:movie];


then


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

NSError *error = [[notification userInfo] objectForKey:@"error"];

if (error) {

NSLog(@"Did finish with error: %@", error);

}

}


add the MediaPlayer.framework to your project &

add to your .h

#import <MediaPlayer/MediaPlayer.h>



Hope this helps

Jul 25, 2013 2:05 PM in response to _nosaj

Many thanks _nosaj,


I have tried the code above...but I continue to get the same problem. The moviePlayer opens. The video does not play and then it closes again. I get the same error message too.


I have taken this code and made it into a sample project. Please feel free to have a look and see if you can see where the problem lies.


https://www.dropbox.com/s/zrbyrop0v4oc0t1/VideoStreamingTest.zip


Thanks for your help on this,


James

Jul 25, 2013 3:46 PM in response to james_coleman01

I'm not very experienced, but if you are going to use internet resources, I would switch over to an HTML browser and let the server handle the behavior. That way your users won't be limited to iphone/ipad and the code will have more local control over the resources.


It makes more sense for the future to think of most iOS apps potential as being equal to the potential of specialized browsers design in conjunction with either private or public networks.


Thinking of iOS devices as 'mini-computers' is not a reasonable direction to endorse.

Streaming video from server....Not easy..help would be appreciated!

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.