I'm attempting to run a local GCDWebServer to serve up an M3U8 file I have stored locally from a server. I parsed the file and saved each .ts file to local storage. Now I'm trying to serve that file up through a local web server, but I'm unable to get the file to play using either MPMoviePlayerController or AVPlayerViewController.
Here is my server code:
webServer = [[GCDWebServer alloc] init];
[webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDirectory = [paths objectAtIndex:0];
NSString *textPath = [docDirectory stringByAppendingPathComponent:@"localPlaylist.m3u8"];
return [GCDWebServerDataResponse responseWithData:[NSData dataWithContentsOfFile:textPath] contentType:@".m3u8"];
}];
[webServer startWithPort:8080 bonjourName:nil];
and my subsequent attempt to play the code:
AVPlayerViewController *newPlayer = [[AVPlayerViewController alloc] init];
newPlayer.player = [[AVPlayer alloc]initWithURL:webServer.serverURL];
[self presentViewController:newPlayer animated:YES completion:nil];
Is there anything I'm doing wrong in the way I'm serving up the local m3u8 file? Also, is running a local web server a secure way to host content?