Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-17-2011, 11:26 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 6
ralph.zhouyuan is on a distinguished road
Default how to initialize a video object using the data loaded from a Socket connection - iOS

hi,
I'm trying to stream a video (H264) across a network on iOS. However, I'm getting the video data(NSData) into a buffer through an open socket to the remote server (using serverSocket), so I don't have a URL to the video that I can use to create an MPMoviePlayerController. How can I initialize and play the video on my iPhone/iPad in this way?

Here is the code:

NSString *requestString = textField_.text;
NSString *url = @"http://192.168.3.11:10000";
NSData *myRequestData = [NSData dataWithBytes:[requestString UTF8String] length:[requestString length]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:myRequestData];

NSURLResponse *response = nil;
NSError *error = nil;

//send the request and get the response from the server.
NSData *content = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

pragma mark--
pragma mark--test video

//parse the content(NSData) into NSString.
NSString *string = [[NSString alloc] initWithData:content encoding:NSASCIIStringEncoding];

//and then into NSURL.
NSURL *url2 = [NSURL URLWithString:string];

//so that it can be used by MPMoivePlayerController.
player_ = [[MPMoviePlayerController alloc] initWithContentURL:url2];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback
name:MPMoviePlayerPlaybackDidFinishNotification objectlayer_];
player_.shouldAutoplay = NO;
player_.repeatMode = YES;
player_.view.frame = CGRectMake(10, 10, 300, 300);
[self.view addSubviewlayer_.view];
[player_ play];


The problem is: I can get data from the content(NSData),which means the server side is ok. But I don't know how to extract the data from NSData into NSString and then into NSURL so that eventually it could be used by MPMoviePlayerController.

Any help would be appreciated.
Thank you very much in advance!

Last edited by ralph.zhouyuan; 09-18-2011 at 06:54 AM.
ralph.zhouyuan is offline   Reply With Quote
Old 09-19-2011, 04:15 AM   #2 (permalink)
Is this a peanut, doctor?
 
Join Date: Apr 2011
Location: Copenhagen
Posts: 254
teCma is on a distinguished road
Default

Please use the code wrap (:
teCma is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, mpmovieplayercontroller, server, socket, video

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 400
16 members and 384 guests
7twenty7, Eclectic, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, JackReidy, jarv, pbart, Pudding, sacha1996, teebee74, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:11 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0