play video from URL retrieved from ALAsset in iOS

眉间皱痕 提交于 2019-12-04 11:54:25
go2

Even easier

MPMoviePlayerViewController *moviePlayerVC =[[MPMoviePlayerViewController alloc] initWithContentURL:[[asset defaultRepresentation] url]];
NSDestr0yer

Okay I found out one can use this block to spit out a log of the asset library address:

void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) 
{

   if(result != nil) {
        NSLog(@"See Asset: %@", result);
        [assets addObject:result];

    }
};

which will spit out something like

"See Asset: ALAsset - Type:Video, URLs:{
    "com.apple.m4v-video" = "assets-library://asset/asset.m4v?id=100&ext=m4v";    "

So I can send this asset library address to MPMoviePlayerController and it will work!

Like so:

NSString *urlAddress = @"assets-library://asset/asset.m4v?id=100&ext=m4v";
NSURL *theURL = [NSURL URLWithString:urlAddress];
mp =  [[MPMoviePlayerController alloc] initWithContentURL:theURL];
etc...

now I just gotta figure out how to get that URL string out of the ALAsset object dynamically, which shouldn't be too hard to figure out.. hopefully

Rob

You can get the url of an asset by using:

[result defaultRepresentation] url];

@go2 answer is correct but The MoviePlayerController doesn't show anything.

so you also need to add moviePlayerController.movieSourceType=MPMovieSourceTypeFile; see below code to play this.

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:self.view.frame];
moviePlayerController.movieSourceType=MPMovieSourceTypeFile;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!