1

ビデオをフォトアルバムに保存するために使用される次のコード。

else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
    {

        NSString *sourcePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"]relativePath]; 
        UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);
    }

動画なら再生したい画像なら表示したい。

助けて。

4

2 に答える 2

1

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)infoメソッドで、ビデオの URL を取得して再生できます。

@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];
}

もちろん、インポートする必要がありますMediaPlayer.framework

編集:現在、Cocoa プロジェクトの大部分は を使用しているため、上記のコードではインスタンスを自分arcで保持する必要があります(この回答で述べたように)。MPMoviePlayerController

于 2012-04-04T07:10:22.313 に答える
1

画像またはビデオであるかどうかをコードで確認します。

    NSString *mediaType1 = [info objectForKey:UIImagePickerControllerMediaType];
    NSLog(@"mediaType : %@",mediaType1);

    if ([mediaType1 isEqualToString:@"public.image"])
    {
        //Show Image
}
else
{
    //show Video
}

ビデオを再生するには、URLを確認してください。

編集:

        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];
}
于 2012-04-04T07:03:54.383 に答える