用的第三方有CocoaHTTPServer,ASIHTTPRequest2
//
// AppDelegate.h
// TestM3U8
//
//
//
// Created by
王聪
on 14-3-14.
// Copyright (c) 2014
年
王聪
. All rights reserved.
//
#import
#import "HTTPServer.h"
@interface AppDelegate : UIResponder <</span>UIApplicationDelegate>
{
HTTPServer *httpServer;
}
@property (strong, nonatomic) UIWindow *window;
#import
#import "HTTPServer.h"
@interface AppDelegate : UIResponder <</span>UIApplicationDelegate>
{
}
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// TestM3U8
//
// Created by on 14-3-14.
// Copyright (c) 2014年 . All rights reserved.
//
#import "AppDelegate.h"
#define kPathDownload @"Downloads"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp tions:(NSDictionary *)launchOptions
{
// m3u8文件下载好之后,得搭建本地服务器
httpServer = [[HTTPServer alloc] init];
// 设置服务器类型为tcp
[httpServer setType:@"_http._tcp."];
// 设置本地服务器端口号,你可以随意设置端口号
[httpServer setPort:12345];
NSString *pathPrefix = [NSSearchPathForDirectori esInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString *webPath = [pathPrefix stringByAppendingPathCom ponent:kPathDownload];
NSLog(@"Setting document root: %@", webPath);
// 指定本地服务器播放的文件路径
[httpServer setDocumentRoot:webPath];
NSError *error;
if(![httpServer start:&error])
{
NSLog(@"Error starting HTTP Server: %@", error);
}
// Override point for customization after application launch.
return YES;
}
//
//
//
//
//
//
#import "AppDelegate.h"
#define kPathDownload @"Downloads"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
{
//
[httpServer setType:@"_http._tcp."];
NSLog(@"Setting document root: %@", webPath);
//
[httpServer setDocumentRoot:webPath];
NSError *error;
if(![httpServer start:&error])
{
NSLog(@"Error starting HTTP Server: %@", error);
}
}
@end
//
// ViewController.h
// TestM3U8
//
// Created by 侯志超 on 14-3-14.
// Copyright (c) 2015年 侯志超. All rights reserved.
//
#import
#import "M3U8Handler.h"
#import "VideoDownloader.h"
@interface ViewController :UIViewController<</span>M3U8HandlerDelegate,VideoDownloadDelegate>
@end
//
//
//
//
//
//
#import
#import "M3U8Handler.h"
#import "VideoDownloader.h"
@interface ViewController :UIViewController<</span>M3U8HandlerDelegate,VideoDownloadDelegate>
@end
//
// ViewController.m
// TestM3U8
//
//
//
// Created by 王聪
on 14-3-14.
// Copyright (c) 2014
年
王聪. All rights reserved.
//
#import "ViewController.h"
#import "M3U8Handler.h"
#import "M3U8Playlist.h"
#import "VideoDownloader.h"
#import
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
// 这个方法是利用ASI把m3u8文件中的地址分别进行请求数据,变成分段的视频
-(void)praseM3U8Finished:(M3U8Handler*)handler
{
handler.playlist.uuid = @"moive5";
VideoDownloader *downloader = [[VideoDownloaderalloc]initWithM3U8List:handler.playlist];
downloader.delegate = self;
[downloader startDownloadVideo];
}
// 全部片段都下载好之后的回调方法
-(void)videoDownloaderFinished:(VideoDownloader*)request
{
// 创建本地播放的m3u8文件
[request createLocalM3U8file];
NSLog(@"everything ok");
}
- (IBAction)start:(id)sender {
#import "ViewController.h"
#import "M3U8Handler.h"
#import "M3U8Playlist.h"
#import "VideoDownloader.h"
#import
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
}
//
-(void)praseM3U8Finished:(M3U8Handler*)handler
{
}
//
-(void)videoDownloaderFinished:(VideoDownloader*)request
{
}
- (IBAction)start:(id)sender {
}
- (IBAction)play:(id)sender {
}
- (void)didReceiveMemoryWarning
{
}
@end