Progressive Download (pseudo-streaming media)
Between the download local playback and live streaming media a form of play, download local playback must all download the file before playing, and progressive download does not have to wait until all the download is complete before playing, it can be downloaded while playing, after the completion of the content, the entire file will be saved on the phone.
Live Streaming media
Real-time streaming is the one side of the receiving packet playback, the local does not keep the file copy, live streaming is always real-time transmission, real-time live broadcast, support random access, users can fast forward or rewind to view the front or back of the content. Real-time streaming media transmission must ensure that the transmission speed of the packet is greater than the speed of the file, or the user will see a video pause. Video quality degrades when the network is plugged, so it's better to ensure that the quality of the video is progressively downloaded.
Real-time Streaming media protocol:
RTSP (Real time streaming Protocol)
MMS (Microsoft Media Server Protocol)
HLS (Http Live streaming)
Here is the main introduction of HLS,
HLS (HTTP Live streaming) is an HTTP-based streaming solution developed by Apple for mobile devices such as the iphone, IPod, itouch and ipad
https://developer.apple.com/streaming/
Technical key points
1. Capture data from video sources and audio sources
2. H264 encoding and AAC encoding of raw data
3. Video and audio data encapsulated as Mpeg-ts package
4.HLS segmentation Generation Strategy and m3u8 index file
5.HTTP Transport Protocol
Setting up HLS Streaming media server
Apache HTTP Server (Apple comes with)
Tomcat Web Server
IIS (Internet information Services)
Only Apache HTTP Server is recommended here
Open Terminal, vi/etc/apache2/httpd.conf
under the <ifmodule mime_module>
Add two lines
AddType application/x-mpegurl.m3u8
AddType video/mp2t.ts
Perhaps you have insufficient authority, then use sudo chmod 777/etc/apache2/httpd.conf
Then vi/etc/apache2/httpd.conf
Restarting the server
sudo apachectl restart
==============================================
or build XMPP server or not set up, favorably get m3u8
==============================================
Create a project
Download library from git: Http://git.oschina.net/1213125967/HLS
Import a library into a project
Need to introduce a third party open source framework: asihttprequest,cocoahttpserver,m3u8
The system framework needs to be imported: Libsqlite3.dylib, Libz.dylib, Libxml2.dylib, Coretelephony.framework, Systemconfiguration.framework, Mobilecoreservices.framework, Security.framework, Cfnetwork.framework, mediaplayer.framework
Add/USR/INCLUDE/LIBXML2 to the library search path
Add header File
#import <MediaPlayer/MediaPlayer.h> #import "M3U8Handler.h" #import "VideoDownloader.h" #import "HTTPServer.h"
Declaring attributes:
@property (nonatomic, Strong) httpserver * httpserver; @property (nonatomic, strong) VideoDownloader *downloader;
Pre-play, Piscian set up the server
#pragma mark - open local server- (void) openhttpserver{ self.httpserver = [[httpserver alloc] init]; [self.httpserver settype:@ "_http._tcp."]; // Set Service type [self.httpServer setPort:12345]; // set server port // get local documents path nsstring * Pathprefix = [nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask,yes) objectatindex:0]; // get local documents path under downloads path nsstring *webpath = [pathprefix stringbyappendingpathcomponent: Kpathdownload]; nslog (@ "-------------\nsetting document root: %@\n", webpath); // Set the server path [self.httpserver setdocumentroot:webpath]; nserror *Error; if (![ Self.httpserver start:&error]) { nslog (@ "-------------\ Nerror starting http server: %@\n ", error);}}
When the building is finished, what is played depends on the needs
Stream Media Playback Online
Youku Video m3u8 The new address format is as follows: Http://pl.youku.com/playlist/m3u8?vid=XNzIwMDE5NzI4&type=mp4//If the link above is not available, use this link/HTTP// v.youku.com/player/getm3u8/vid/xnziwmde5nzi4/type/flv Nsurl *url = [[Nsurl alloc] initwithstring:@ "/HTTP/ V.youku.com/player/getm3u8/vid/xnziwmde5nzi4/type/mp4 "]; Mpmovieplayerviewcontroller *player = [[Mpmovieplayerviewcontroller alloc] initwithcontenturl:url]; [Self presentmovieplayerviewcontrolleranimated:player];
Video download
M3u8handler *handler = [[M3u8handler alloc] init]; Handler.delegate = self; Parsing m3u8 video Address [handler praseurl:[nsstring stringwithformat:@ "http://pl.youku.com/playlist/m3u8?vid=XNzIwMDE5NzI4 &type=mp4 "]; Turn on the network indicator [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:yes];
Play local video
nsstring * playurl = [nsstring stringwithformat:@ "/http 127.0.0.1:12345/xnziwmde5nzi4/movie.m3u8 "]; nslog (@" Local Video address-----%@ ", playurl); // get local documents path nsstring * Pathprefix = [nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsuserdomainmask,yes) objectatindex:0]; // get local documents path under downloads path NSString *localDownloadsPath = [pathPrefix stringbyappendingpathcomponent:kpathdownload]; // Get video Local Path NSString *filePath = [localDownloadsPath stringbyappendingpathcomponent:@ "xnziwmde5nzi4/movie.m3u8"]; nsfilemanager * Filemanager = [nsfilemanager defaultmanager]; // determines if the video cache is complete, and if it is done, plays the local cache if ([filemanager Fileexistsatpath:filepath]) { mpmovieplayerviewcontroller *playerViewController =[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL urlwithstring: playurl]]; [self presentmovieplayerviewcontrolleranimated:playerviewcontroller]; } else{ uialertview *alertview = [[ uialertview alloc] initwithtitle:@ "Sorry" message:@ "current video not Cached" delegate:self cancelbuttontitle:@ "OK" otherButtonTitles:nil, nil]; [Alertview show]; }
Add Agent <M3U8HandlerDelegate,VideoDownloadDelegate>
#pragma mark --------------Video parsing complete-----------------(void) prasem3u8finished: (m3u8handler*) handler{ handler.playlist.uuid = @ "Xnziwmde5nzi4"; self.downloader = [[videodownloader alloc]initwithm3u8list:handler.playlist]; [self.downloader addobserver:self forkeypath:@ "Totalprogress" options: nskeyvalueobservingoptionnew | nskeyvalueobservingoptionold context:nil]; self.downloader.delegate = self; [self.downloader Startdownloadvideo];} -(void) Observevalueforkeypath: (nsstring *) Keypath ofobject: (ID) Object change: (NSDictionary *) Change context: (void *) Context{ nslog (@ "Download Progress - %f", self.downloader.totalprogress);} #pragma mark --------------Video parsing failed-----------------(void) prasem3u8failed: (m3u8handler*) handler{ NSLog (@ "video parsing failed-failed -- %@", handler);} #pragma mark --------------Video download complete-----------------(void) videodownloaderfinished: (videodownloader*) request{ [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no]; [request createlocalm3u8file]; nslog (@ "----------video download Completed-------------");} #pragma mark --------------video download failed-----------------(void) videodownloaderfailed: (videodownloader*) Request{ nslog (@ "----------video download Failed-----------");}