2012-01-18 5 views
-1

私は、ダイナミックな映像のためのコードを書いたことが文書に格納されるべきであり、ドキュメントフォルダーに動画を保存する方法は?次のコード

UIImagePickerController *ipc = [[UIImagePickerController alloc] init]; 
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
ipc.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType]; 
ipc.delegate = self; 
ipc.editing = NO; 
[self presentModalViewController:ipc animated:YES]; 

答えて

-1

私たちのプログラムでそれを以下のコードを、そのビデオの任意のwherを使用するお手伝いをします、

#pragma mark UIImagePickerControllerDelegate 

- (void)imagePickerController:(UIImagePickerController *)imagePickerControl didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

    NSURL *videoURL; 
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; 
    if ([type isEqualToString:(NSString *)kUTTypeVideo] || 
     [type isEqualToString:(NSString *)kUTTypeMovie]) 
    { 
     videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 

    } 
    [self saveVideoToFileFromURL:videoURL]; 
    [self dismissModalViewControllerAnimated:YES]; 

} 

-(void)saveVideoToFileFromURL:(NSURL*)videoStorageURL 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSDate *todayDateObj = [NSDate date]; 
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat:@"ddMMyyyyHHmmss"];  
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"movie%@.mov",[dateFormat stringFromDate:todayDateObj]] ]; 
    [dateFormat release]; 

    NSData *data = [NSData dataWithContentsOfURL:videoStorageURL]; 
    [data writeToFile:filePath atomically:YES]; 

} 
-1

この方法は、AppDelegateの.mファイルにコードを挿入後AppDelegate.hファイル

@property (nonatomic , retain) MPMoviePlayerViewController *mPlayer; 
-(void)initAndPlayMovie:(NSURL *)movieURL andViewController:(UIViewController*)vCtr; 

に挿入

プラグママーク - メディアプレーヤー

-(void)initAndPlayMovie:(NSURL *)movieURL andViewController:(UIViewController*)vCtr 
{ 
    self.mPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; 
    // set source type streaming 
    [self.mPlayer.moviePlayer setMovieSourceType:MPMovieSourceTypeUnknown]; 

    [self.mPlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen]; 

    // fit to screen mode 
    [self.mPlayer.moviePlayer setScalingMode:MPMovieScalingModeAspectFit]; 

    // full screen mode 
    [self.mPlayer.moviePlayer setFullscreen:YES animated:YES]; 

    [vCtr presentMoviePlayerViewControllerAnimated:self.mPlayer]; 
} 

-(void)stopPlaying_dismissMoviePlayer 
{ 
    [self.mPlayer.moviePlayer stop]; 
    [self.mPlayer dismissMoviePlayerViewControllerAnimated]; 
} 

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{ 
    [self stopPlaying_dismissMoviePlayer]; 
} 

.hファイルにコードを挿入後

#import <UIKit/UIKit.h> 

#import <AVFoundation/AVAudioPlayer.h> 
#import "ASIHTTPRequest.h" 
#import "ASIDownloadCache.h" 

@interface locallyCacheMP3FileViewController : UIViewController 

- (IBAction)playAudio:(UIButton*)sender; 

@property (nonatomic, retain) ASIHTTPRequest *rqstForAudio; 

@end 

は、ボタンのプレスイベントに接続playAudioとして変数

@synthesize rqstForAudio=_rqstForAudio; 

Createメソッド名を合成。

#pragma mark - View lifecycle 

- (IBAction)playAudio:(UIButton*)sender 
{ 

    NSString *[email protected]"Your Video link"; 

    // check first locally exists or not 
    NSString *strPathToAudioCache=[NSString stringWithFormat:@"%@/%@", 
            [(NSArray*)NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], 
            AudioFolder]; 

    NSDictionary *dOfAudios=[NSDictionary dictionaryWithContentsOfFile:strPathToAudioCache]; 

    if([dOfAudios valueForKey:strAudioURL]) { 
     [APP_DEL initAndPlayMovie:[NSURL fileURLWithPath:[dOfAudios valueForKey:strAudioURL]] andViewController:self]; 
    } else { 
     NSURL *audioURL = [NSURL URLWithString:strAudioURL]; 
     NSString *strPathToDownload=[NSString stringWithFormat:@"%@/%@",[(NSArray*)NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], 
            [strAudioURL lastPathComponent]]; 

     if(!self.rqstForAudio || [self.rqstForAudio isFinished]) { 
      self.rqstForAudio=[ASIHTTPRequest requestWithURL:audioURL]; 
      [self.rqstForAudio setDelegate:self]; 
      [self.rqstForAudio setAllowResumeForFileDownloads:YES]; 
      [self.rqstForAudio setCachePolicy:ASIUseDefaultCachePolicy]; 
      [self.rqstForAudio setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy]; 
      [self.rqstForAudio setDidFailSelector:@selector(failedToLoad:)]; 
      [self.rqstForAudio setDidFinishSelector:@selector(finishedLoading:)]; 
      [self.rqstForAudio setDownloadCache:[ASIDownloadCache sharedCache]]; 
      [self.rqstForAudio setDownloadDestinationPath:strPathToDownload]; 
      [self.rqstForAudio startAsynchronous]; 
     } 

    } 
} 

You can download the Source code and tutorial here

関連する問題