<i id='r3pgy'><tr id='r3pgy'><dt id='r3pgy'><q id='r3pgy'><span id='r3pgy'><b id='r3pgy'><form id='r3pgy'><ins id='r3pgy'></ins><ul id='r3pgy'></ul><sub id='r3pgy'></sub></form><legend id='r3pgy'></legend><bdo id='r3pgy'><pre id='r3pgy'><center id='r3pgy'></center></pre></bdo></b><th id='r3pgy'></th></span></q></dt></tr></i><div id='r3pgy'><tfoot id='r3pgy'></tfoot><dl id='r3pgy'><fieldset id='r3pgy'></fieldset></dl></div>

    <tfoot id='r3pgy'></tfoot>
      <bdo id='r3pgy'></bdo><ul id='r3pgy'></ul>

    <small id='r3pgy'></small><noframes id='r3pgy'>

  1. <legend id='r3pgy'><style id='r3pgy'><dir id='r3pgy'><q id='r3pgy'></q></dir></style></legend>
    1. 如何从资产网址保存视频

      时间:2023-10-23
        <tbody id='dDaDM'></tbody>
      <legend id='dDaDM'><style id='dDaDM'><dir id='dDaDM'><q id='dDaDM'></q></dir></style></legend>
      <i id='dDaDM'><tr id='dDaDM'><dt id='dDaDM'><q id='dDaDM'><span id='dDaDM'><b id='dDaDM'><form id='dDaDM'><ins id='dDaDM'></ins><ul id='dDaDM'></ul><sub id='dDaDM'></sub></form><legend id='dDaDM'></legend><bdo id='dDaDM'><pre id='dDaDM'><center id='dDaDM'></center></pre></bdo></b><th id='dDaDM'></th></span></q></dt></tr></i><div id='dDaDM'><tfoot id='dDaDM'></tfoot><dl id='dDaDM'><fieldset id='dDaDM'></fieldset></dl></div>
      • <bdo id='dDaDM'></bdo><ul id='dDaDM'></ul>

            <tfoot id='dDaDM'></tfoot>

              • <small id='dDaDM'></small><noframes id='dDaDM'>

                本文介绍了如何从资产网址保存视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想从资产 url 将视频保存到我的应用文档中.我的资产网址如下:-

                "assets-library://asset/asset.MOV?id=1000000394&ext=MOV"

                我试过这个:-

                NSString *str=@"assets-library://asset/asset.MOV?id=1000000394&ext=MOV";NSData *videoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];[videoData writeToFile:mypath atomically:YES];

                但是在第二行 [NSData dataWithContentsOfURL:[NSURL URLWithString:str]] 我得到了程序崩溃的原因:-由于未捕获的异常NSInvalidArgumentException"而终止应用,原因:'-[NSURL 长度]:无法识别的选择器已发送到实例

                我想知道如何访问资产视频网址.

                感谢任何帮助.

                解决方案

                我认为你最好的办法是使用方法

                getBytes:fromOffset:length:error:

                ALAssetRepresentation

                你可以像这样获得资产的默认表示

                ALAssetRepresentation *representation = [someVideoAsset defaultRepresentation];

                所以我想它应该是这样的(我不在我的 Mac 上,所以这个还没有经过测试)

                ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];[assetLibraryassetForURL:videoUrl resultBlock:^(ALAsset *asset) {ALAssetRepresentation *rep = [资产 defaultRepresentation];字节 *buffer = (Byte*)malloc(rep.size);NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];[数据 writeToFile:filePath atomically:YES];} 错误块:^(NSError *err){NSLog(@"错误: %@",[错误的本地化描述]);}];

                videoUrl 是您要复制的视频的资产 url,filePath 是您要保存的路径.p>

                I want to save video to my app document from asset url. My asset url is as follows:-

                "assets-library://asset/asset.MOV?id=1000000394&ext=MOV"
                

                I tried this:-

                NSString *str=@"assets-library://asset/asset.MOV?id=1000000394&ext=MOV";
                NSData *videoData = [NSData dataWithContentsOfURL:[NSURL URLWithString:str]];
                [videoData writeToFile:mypath atomically:YES];
                

                but on the second line [NSData dataWithContentsOfURL:[NSURL URLWithString:str]] i got program crash with this reason:- Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance

                I want to know how to access asset video url.

                Thanx for any help.

                解决方案

                I think your best bet is to use the method

                getBytes:fromOffset:length:error:
                

                of

                ALAssetRepresentation
                

                You can get the default representation of an asset like so

                ALAssetRepresentation *representation = [someVideoAsset defaultRepresentation];
                

                So off the top of my head it should go something like this (I'm away from my Mac so this hasn't been tested)

                ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
                [assetLibrary assetForURL:videoUrl resultBlock:^(ALAsset *asset) {
                    ALAssetRepresentation *rep = [asset defaultRepresentation];
                    Byte *buffer = (Byte*)malloc(rep.size);
                    NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
                    NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
                    [data writeToFile:filePath atomically:YES];
                } errorBlock:^(NSError *err) {
                    NSLog(@"Error: %@",[err localizedDescription]);
                }];
                

                Where videoUrl is the asset url of the video you're trying to copy, and filePath is the path where you're trying to save it to.

                这篇关于如何从资产网址保存视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:NSString 到 NSurl 下一篇:NSFetchedResultsController 忽略 fetchLimit?

                相关文章

                <i id='gnSY0'><tr id='gnSY0'><dt id='gnSY0'><q id='gnSY0'><span id='gnSY0'><b id='gnSY0'><form id='gnSY0'><ins id='gnSY0'></ins><ul id='gnSY0'></ul><sub id='gnSY0'></sub></form><legend id='gnSY0'></legend><bdo id='gnSY0'><pre id='gnSY0'><center id='gnSY0'></center></pre></bdo></b><th id='gnSY0'></th></span></q></dt></tr></i><div id='gnSY0'><tfoot id='gnSY0'></tfoot><dl id='gnSY0'><fieldset id='gnSY0'></fieldset></dl></div>

                <legend id='gnSY0'><style id='gnSY0'><dir id='gnSY0'><q id='gnSY0'></q></dir></style></legend>
                  <bdo id='gnSY0'></bdo><ul id='gnSY0'></ul>

                1. <tfoot id='gnSY0'></tfoot>

                  <small id='gnSY0'></small><noframes id='gnSY0'>