Der folgende Code zum Speichern von Videos im Fotoalbum.Wie greife ich auf Videos aus dem Fotoalbum zu und spiele sie ab?
Wenn es Video ist, möchte ich es spielen, wenn es Bild ist, das ich es anzeigen möchte.
Hilf mir.
Der folgende Code zum Speichern von Videos im Fotoalbum.Wie greife ich auf Videos aus dem Fotoalbum zu und spiele sie ab?
Wenn es Video ist, möchte ich es spielen, wenn es Bild ist, das ich es anzeigen möchte.
Hilf mir.
mit dem Code zu überprüfen, ob das Bild oder Video ist:
NSString *mediaType1 = [info objectForKey:UIImagePickerControllerMediaType];
NSLog(@"mediaType : %@",mediaType1);
if ([mediaType1 isEqualToString:@"public.image"])
{
//Show Image
}
else
{
//show Video
}
um das Video abzuspielen, die URL überprüfen.
EDIT:
NSString *moviePath = [bundle pathForResource:@"IMG_0017" ofType:@"MOV"];
NSLog(@"moviePath : %@",moviePath);
// NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
NSURL *movieURL = [NSURL URLWithString:strValURL];
NSLog(@"movieURL : %@",movieURL);
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2)
{
NSLog(@"> 3.2");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
if (mp)
{
[self presentMoviePlayerViewControllerAnimated:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mp.moviePlayer play];
[mp release];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2)
{
NSLog(@"< 3.2");
theMovie = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[theMovie play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
}
In Ihrem - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
Methode können Sie die URL des Videos bekommen, und es spielen:
@property (nonatomic,retain) MPMoviePlayerController *moviePlayerController;
if ([mediaType isEqualToString:@"public.movie"])
{
NSURL *aURL = [info objectForKey:UIImagePickerControllerMediaURL];//get the url
// and init the video player using this url
_moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:aURL];
[self.view _moviePlayerController.view];
_moviePlayerController.useApplicationAudioSession = NO;
_moviePlayerController.fullscreen = YES;
[_moviePlayerController play];
}
Natürlich werden Sie die MediaPlayer.framework
importieren müssen
EDIT: Eine Mehrheit der Cocoa-Projekte verwenden jetzt arc
, so dass der obige Code erfordert, dass Sie die MPMoviePlayerController
Instanz selbst behalten (wie in this answer erwähnt).
Es spielt kein Video – Shreedhar
@Shreedhar Ich habe dies in der '- (void) imagePickerController: (UIImagePickerController *) Picker didFinishPickingMediaWithInfo: (NSDictionary *) info' Methode. – tipycalFlow
Funktioniert nicht ... – c0d3Junk13
Versuchen Sie den aktualisierten Code .. !! – Sarah