Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Browser/AVExtractor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// AVExtractor.m
// Simple DOM-based extractor for common stream patterns
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface AVExtractor : NSObject
+ (NSString *)extractPlayableURLFromWebView:(UIWebView *)webview;
@end

@implementation AVExtractor

+ (NSString *)extractPlayableURLFromWebView:(UIWebView *)webview {
// Run a small JS in the UIWebView to find <video> src or common direct links
NSString *js = @"(function(){ \
var v = document.querySelector('video'); \
if (v) { \
var s = v.currentSrc || v.src; \
if (s) return s; \
var src = (v.querySelector('source')||{}).src; \
if (src) return src; \
} \
var a = document.querySelector('a[href$=\".m3u8\"], a[href$=\".mp4\"], a[href$=\".ts\"]'); \
if (a) return a.href; \
var html = document.documentElement.innerHTML; \
var match = html.match(/https?:\\\\/\\\\/[^\\\"'\\\\s]+\\.m3u8/); \
if (match) return match[0]; \
return ''; \
})();";
@try {
NSString *maybeURL = [webview stringByEvaluatingJavaScriptFromString:js];
if (maybeURL && maybeURL.length > 0) return maybeURL;
} @catch (NSException *ex) {
return nil;
}
return nil;
}

@end
40 changes: 40 additions & 0 deletions Browser/PlayerViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PlayerViewController.h
// AVPlayer
//
// Created by apple on 13-5-22.
// Copyright (c) 2013年 iMoreApp Inc. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <AVPlayerTouch/AVPlayerTouch.h>

@interface PlayerViewController : UIViewController

// audio or video url (local or network)
@property (nonatomic, strong) NSURL *mediaURL;

// input av format name (default is nil)
@property (nonatomic, strong) NSString *avFormatName;

// did load video successfully callback.
@property (nonatomic, copy) void (^didLoadVideo)(FFAVPlayerController *player);

// get start playback time (>= 0 and <= media duration).
// if the property is nil, player will start playback from begining.
// the callback returns a float number value or nil.
@property (nonatomic, copy) NSNumber* (^getStartTime)(FFAVPlayerController *player, NSURL *url);

// required saving progress info, you can save progress here.
@property (nonatomic, copy) void (^saveProgress)(FFAVPlayerController *player);

// on video playback did finish.
@property (nonatomic, copy) void (^didFinishPlayback)(FFAVPlayerController *player);

// on video player controller will be dismissed.
@property (nonatomic, copy) void (^willDismiss)(void);

// Start playback at special time position
- (void)startPlaybackAt:(NSNumber *)startTimePosition;

@end
Loading