Giter Site home page Giter Site logo

dvassetloaderdelegate's Introduction

DVAssetLoaderDelegate

Version License Platform

Description

With DVAssetLoaderDelegate you can implement caching data downloaded by AVPlayer for AVURLAsset. DVAssetLoaderDelegate provides you delegate method you can use to save downloaded data:

- (void)dvAssetLoaderDelegate:(DVAssetLoaderDelegate *)resourceLoader
                  didLoadData:(NSData *)data
                       forURL:(NSURL *)url;

For other methods check DVAssetLoaderDelegatesDelegate.h.

Usage

Easy way (subclassing AVURLAsset)

  1. Create DVURLAsset.
  2. Implement DVURLAsset's loaderDelegate.

Manual way (without subclassing)

  1. Create DVAssetLoaderDelegate object using URL for AVURLAsset.
  2. Set DVAssetLoaderDelegate delegate for receiving cache data.
  3. Before creating AVURLAsset, change URL scheme to [DVAssetLoaderDelegate scheme].
  4. Create AVURLAsset with URL with updated scheme.
  5. Set AVURLAsset's resource loader delegate to created DVAssetLoaderDelegate object.
NSURL *URL = ...;

DVAssetLoaderDelegate *resourceLoaderDelegate = [[DVAssetLoaderDelegate alloc] initWithURL:URL];
resourceLoaderDelegate.delegate = self;


NSURLComponents *components = [[NSURLComponents alloc] initWithURL:URL resolvingAgainstBaseURL:NO];
components.scheme = [DVAssetLoaderDelegate scheme];

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[components URL] options:options];
[asset.resourceLoader setDelegate:resourceLoaderDelegate queue:dispatch_get_main_queue()];

Installation

DVAssetLoaderDelegate is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DVAssetLoaderDelegate'

Author

vdugnist, [email protected]

License

DVAssetLoaderDelegate is available under the MIT license. See the LICENSE file for more info.

dvassetloaderdelegate's People

Contributors

amyhametov avatar n1ru4l avatar vdugnist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dvassetloaderdelegate's Issues

DVURLAsset does not handle URLs with redirects

DVURLAsset times out for the urls with redirect

Example:

     let url = URL(string:"") // URL with 302 redirect
     let asset = DVURLAsset(url: url)
     asset.loaderDelegate = self
     ...
     asset.loadValuesAsynchronously(forKeys: ["playable"]) { [weak self] in
            var error: NSError? = nil
            let status = asset.statusOfValue(forKey: playableKey, error: &error)
            print(error?.localizedDescription) // Code=-1001 "The request timed out.
     }

Expected:
Should load url similar to AVAsset

Actual:
Returns Code=-1001 "The request timed out."

is Disk cache available ?

I wanted to save the cache to disk(Document directory) and when want to play the same url it should take from disk and then should play.

My scenarios:

I wanted to download 3sec of video and should save in cache, when user click play in AVPlayer, disk cached (3sec) video should play first and the remaining video should play from network.

Only Downloading the Contents

Hi ,

Now able to download the contents instead of Playing . I am doing like this..

NSURL *url = [NSURL URLWithString:@"https://videos.bodybuilding.com/video/mp4/62000/62792m.mp4"];
DVURLAsset *asset = [[DVURLAsset alloc] initWithURL:url options:nil];
asset.loaderDelegate = self;

iOS 13

Hi,

I'd recommend to make a such or like this change:

inside the DVAssetLoaderDelegate.m

change

- (NSData *)subdataFromData:(NSData *)data
                 forRequest:(NSURLRequest *)request
                   response:(NSHTTPURLResponse *)response
             loadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest {
    NSString *requestRange = rangeFromRequest(request);
    NSString *responseRange = rangeFromResponse(response);

into


- (NSData *)subdataFromData:(NSData *)data
                 forRequest:(NSURLRequest *)request
                   response:(NSHTTPURLResponse *)response
             loadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest {
    NSString *requestRange = rangeFromRequest(request);
    if (response.statusCode == 200 && [requestRange isEqualToString:@"0-"]) {
        return data;
    }
    NSString *responseRange = rangeFromResponse(response);

because an urlAsset object(at iOS 13) requests a whole content immediately after the "bytes=0-1" request: "bytes=0-"
as it requests a whole range there is no Content-Range in response from server and the received piece of data is not interpreted as valid.

Play from Cached Data and then from URL

Hi ,

Is there support for First play from cache data . If the some data or complete data available then first it should play it and then after through the Network

Error: unsupported url

Hello!
iOS 13 / pod 'DVAssetLoaderDelegate' / using either DVURLAsset(url: originUrl) or AVURLAsset(url: customSchemeUrl) + setting DVAssetLoaderDelegate(url: originUrl) or any other playing with url scheme leads to this error:

Task .<1> finished with error [-1002] Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=DVAssetLoaderDelegate:.mp4, NSErrorFailingURLKey=DVAssetLoaderDelegate:.mp4, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask .<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<1>, NSUnderlyingError=0x600001bf8f90 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}}

*I have replaced confidential url with asterisks

CocoaPod published missing DVURLAsset initWithURL method

Published version:

//
//  DVURLAsset.h
//  DVAssetLoaderDelegate
//
//  Created by Vladislav Dugnist on 07/01/2018.
//

#import <AVFoundation/AVFoundation.h>
#import "DVAssetLoaderDelegatesDelegate.h"

@interface DVURLAsset : AVURLAsset

@property (nonatomic, weak) NSObject <DVAssetLoaderDelegatesDelegate> *loaderDelegate;

@end

Vs repo version:

//
//  DVURLAsset.h
//  DVAssetLoaderDelegate
//
//  Created by Vladislav Dugnist on 07/01/2018.
//

#import <AVFoundation/AVFoundation.h>
#import "DVAssetLoaderDelegatesDelegate.h"

@interface DVURLAsset : AVURLAsset

- (instancetype)initWithURL:(NSURL *)URL options:(NSDictionary<NSString *,id> *)options networkTimeout:(NSTimeInterval)networkTimeout;

@property (nonatomic, weak) NSObject <DVAssetLoaderDelegatesDelegate> *loaderDelegate;

@end

load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled"

Dear,

first, thank you so much for this library. It worked well with audio files, but now, I'm experiencing the follow error with HLS video:

2019-05-03 09:47:13.559307-0300 DVAssetLoaderDelegate_Example[2277:686162] Task <7C20E763-33A8-4F69-BE7F-A5B75353CD99>.
<1> load failed with error Error Domain=NSURLErrorDomain Code=-999 "cancelled"
 UserInfo={NSErrorFailingURLStringKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8, 
NSErrorFailingURLKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8,
 _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <7C20E763-33A8-4F69-BE7F-A5B75353CD99>.<1>"
), _
NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <7C20E763-33A8-4F69-BE7F-A5B75353CD99>.<1>, NSLocalizedDescription=cancelled} [-999]

What I doing is get the sample project and replace de url to https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8 a sample file from apple examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.