Ich bin neu in iOS Entwicklung,Können Sie Video-Stream in
Ich möchte Video-Stream von WebAPI, werden die Dateien gestreamt aus unserem Back-End-Server, die eine Authentifizierung erfordert laden. Es ist schlüsselbasiert authentifiziert im Autorisierungs-HTTP-Header.
Ich versuchte mit AVPlayer hat nicht meine Ausgabe. Nach etwas mehr Forschung zu tun, fand ich customProtocol mehr nützlich sein wird, es zu tun, so habe ich customProtocol und versuchte, mit diesem Code verwendet, aber die customProtocol genannt wird, nicht customProtocol.h, customProtocol.m
[NSURLProtocol registerClass:[MyCustomProtocol class]];
NSString *theURLString = @"customProtocol://abcd.com/download";
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:theURLString]];
[self.view addSubview:player.view];
player.view.frame = self.view.frame;
[player play];
jemand mir helfen, hier kann immer? Wo mache ich einen Fehler?
Vielen Dank im Voraus!
Das ist mein customProtocol Code:
@implementation MyCustomProtocol
+ (BOOL) canInitWithRequest:(NSURLRequest *)request {
NSURL* theURL = request.URL;
NSString* scheme = theURL.scheme;
if([scheme isEqualToString:@"customProtocol"]) {
return YES;
}
return NO;
}
// You could modify the request here, but I'm doing my legwork in startLoading
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
return request;
}
// I'm not doing any custom cache work
+ (BOOL) requestIsCacheEquivalent:(NSURLRequest *)a toRequest:(NSURLRequest *)b {
return [super requestIsCacheEquivalent:a toRequest:b];
}
// This is where I inject my header
// I take the handled request, add a header, and turn it back into http
// Then I fire it off
- (void) startLoading {
NSMutableURLRequest* mutableRequest = [self.request mutableCopy];
Constants *constants = [Constants sharedInstance];
[mutableRequest setValue:[NSString stringWithFormat:@"Bearer %@",constants.access_token] forHTTPHeaderField:@"Authorization"];
NSURL* newUrl = [[NSURL alloc] initWithScheme:@"http" host:[mutableRequest.URL host] path:[mutableRequest.URL path]];
[mutableRequest setURL:newUrl];
self.connection = [NSURLConnection connectionWithRequest:mutableRequest delegate:self];
}
- (void) stopLoading {
[self.connection cancel];
}
// Below are boilerplate delegate implementations
// They are responsible for letting our client (the MPMovePlayerController) what happened
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[self.client URLProtocol:self didFailWithError:error];
self.connection = nil;
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.client URLProtocol:self didLoadData:data];
}
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
[self.client URLProtocolDidFinishLoading:self];
self.connection = nil;
}
ich habe das schon mal kein glück probiert –