HTTP 프로토콜로 비디오 스트리밍 서비스를 구현해야합니다. url을 MPMoviePlayerController에 설정하는 방법과 headerField를 NSMutableURLRequest로 설정하는 방법을 알고 있지만 어떻게 조합해야하는지 잘 모릅니다. 아래의 코드를 구현하지만 작동하지 않습니다. 바이너리 데이터에 파일 정보가 없기 때문에 가정합니다.헤더 정보를 MPMoviePlayerController URL에 삽입하는 방법은 무엇입니까?
- (void) openUrl
{
NSMutableURLRequest *reqURL = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://111.222.33.44/MOV/2013/4/123123123"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
[reqURL setHTTPMethod:@"GET"];
[reqURL setValue:@"Mozilla/4.0 (compatible;)" forHTTPHeaderField:@"User-Agent"];
[reqURL setValue:@"AAA-bb" forHTTPHeaderField:@"Auth-Token"];
[reqURL setValue:@"bytes=0-1024" forHTTPHeaderField:@"Range"];
[reqURL setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[NSURLConnection connectionWithRequest:reqURL delegate:self];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"Received");
NSError * jsonERR = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.ts"];
[data writeToFile:path atomically:YES];
NSLog(@"copied");
NSURL *moveUrl = [NSURL fileURLWithPath:path];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]init];
[player setContentURL:moveUrl];
player.view.frame = self.view.bounds;
player.controlStyle = MPMovieControlStyleEmbedded;
[self.view addSubview:player.view];
[player play];
}
대리자 메서드에 데이터가 있지만 작업 방법을 잘 모르겠습니다. 누군가 제게 어떻게하는지 알려주세요. 인증 토큰 및 범위는 필수 매개 변수입니다.
감사합니다.
그런데 어떻게 처리할까요? – z33