JNYJ

JNYJ - IOS - DEV

 

play video from URL retrieved from ALAsset in iOS

play video from URL retrieved from ALAsset in iOS
youDevise, Ltd. - Pragmatic Programmer London, England
On-Line Strategies, Inc. - Java Software Engineer / Developer Dallas, TX
Mutual Mobile - Software Engineer - Android Austin, TX
TabbedOut - Superhuman Mobile Developer Austin, TX   
up vote
0
down vote
favorite
I'm still fairly new to Obj-C and the idea of blocks. I read this post about displaying images from url retrieved from ALAssets: http://stackoverflow.com/questions/3837115/display-image-from-url-retrieved-from-alasset-in-iphone

Besides being able to view picture files in a UITableView using the ALAsset framework, I want to be able to play a video that is stored in the pictures folder as well. The video asset shows up just as a picture would, so I would like to be able to tap that video listing in the table and have it play. (In other words, I want to play a video using the Assets Library Framework)

Can this be done with MPMoviePlayerController?

From that post above I'm gathering I need code inside this function to get an asset URL for a video file: ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { };

If this is right, what code would I need to put inside that function so that I could successfully play the video via mpmovieplayercontroller?

Just for reference, my code for displaying the assets in a UITableView is here: " - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"id";

UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[[cell imageView] setImage:[UIImage imageWithCGImage:[[assets objectAtIndex:indexPath.row] thumbnail]]]; [[cell textLabel] setText:[NSString stringWithFormat:@"Item %d", indexPath.row+1]];

return cell;
} "

This is my first post so I'm sorry if I post it wrong. Thanks for your help

iphone url video ios mpmovieplayercontroller
link|edit|flag
asked Oct 5 '10 at 15:21
Kevin Williams
204
2 Answersactiveoldestvotes
up vote
1
down vote
accepted
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

link|edit|flag
answered Oct 5 '10 at 16:12
Kevin Williams
204

up vote
0
down vote
Even easier

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

link|edit|flag



Address: http://stackoverflow.com/questions/3865110/play-video-from-url-retrieved-from-alasset-in-ios

posted on 2011-04-19 11:31  JNYJ  阅读(1949)  评论(0编辑  收藏  举报

导航