I am trying to run a local GCDWebServer to work with an M3U8 file that I saved locally from the server. I parsed the file and saved each .ts file to local storage. Now I am trying to serve this file through a local web server, but I can not get the file to play using 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 reproduce the code:
AVPlayerViewController *newPlayer = [[AVPlayerViewController alloc] init]; newPlayer.player = [[AVPlayer alloc]initWithURL:webServer.serverURL]; [self presentViewController:newPlayer animated:YES completion:nil];
Is there something that I am doing wrong in the way I maintain the local m3u8 file? Also, does the local web server work in a safe way to host content?
source share