2012-02-21 6 views
0

ASIHTTPRequestを使用して画像とビデオをWebサービスにアップロードするiPhoneアプリがあります。すべてがiOS 5を実行しているデバイスではうまく動作しますが、UIImagePickerControllerから戻って4.3以降のデバイスでクラッシュします。ビデオは圧縮されているので、アプリケーションがクラッシュします。以下は、 - (void)imagePickerController:didFinishPickingMediaWithInfo:メソッドのコードです。また、ビデオをサーバーに送信するメソッドと、ビデオからサムネイルとして使用するイメージをキャプチャするメソッドもあります。 4.3でクラッシュの原因となっていることに関するアイデアはありますか?この問題へビデオのアップロード時にiOS 4.3がクラッシュする

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

self.mediaType = [info objectForKey:UIImagePickerControllerMediaType]; 

if ([self.mediaType isEqualToString:(NSString *)kUTTypeMovie]) 
{ 
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; 

    // Get asset to use for orientation determination 
    AVAsset *myAsset = [AVAsset assetWithURL:videoURL]; 

    self.videoOrientation = [self UIInterfaceOrientationToString:[self orientationForTrack:myAsset]]; 

    UIImage *videoThumbnail = [self getVideoThumbnailFromAVAsset:myAsset]; 
    self.photoImageView.image = videoThumbnail; 

    self.videoData = [[NSMutableData alloc]initWithContentsOfURL:videoURL]; 
} 
[self dismissModalViewControllerAnimated:YES]; 
} 

-(UIImage*)getVideoThumbnailFromAVAsset:(AVAsset *)myAsset { 
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:myAsset]; 

Float64 durationSeconds = CMTimeGetSeconds([myAsset duration]); 
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600); 
NSError *error = nil; 
CMTime actualTime; 
UIImage *myImage; 

CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error]; 

if (halfWayImage != NULL) { 
    myImage = [UIImage imageWithCGImage:halfWayImage]; 
    CGImageRelease(halfWayImage); 
} 
return myImage; 
} 

- (void)postMessage:(id)sender { 

self.uploadButton.enabled = NO; 
[self.descriptionTextField resignFirstResponder]; 
[self.titleTextField resignFirstResponder]; 

NSUserDefaults *settings = [NSUserDefaults standardUserDefaults]; 
NSString *sessionKey = [settings stringForKey: @"sessionKey"]; 

// build URL for request 
NSString *baseURL; 
NSString *endPoint; 

// code here that creates the url component strings baseURL and endPoint 

NSString *fullURL = [NSString stringWithFormat:@"%@%@", baseURL, endPoint]; 
NSURL *url = [NSURL URLWithString:fullURL]; 

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
request.postFormat = ASIMultipartFormDataPostFormat; 

NSString *teamIDStr = [NSString stringWithFormat:@"%d",[self.teamID intValue]]; 

[request setPostValue:sessionKey forKey:@"sessionKey"]; 
[request setPostValue:teamIDStr forKey:@"TeamID"]; 
[request setPostValue:titleTextField.text forKey:@"lessonName"]; 
[request setPostValue:descriptionTextField.text forKey:@"lessonDesc"]; 
[request setPostValue:self.videoOrientation forKey:@"videoOrientation"]; 

//create video file name 
NSDate *date1=[NSDate date]; 
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init]; 
[formatter1 setDateFormat:@"hhmm"]; 
NSString *valuestr = [formatter1 stringFromDate:date1]; 
NSString *moviename = [NSString stringWithFormat:@"video_%@.mov", valuestr]; 

[request setData:self.videoData withFileName:moviename andContentType:@"video/quicktime" forKey:@"file1.mov"]; 

[request setUploadProgressDelegate:self.progressBar]; 
[request setShowAccurateProgress:YES]; 
self.progressBar.hidden = NO; 
[request setDelegate:self]; 
[request setTimeOutSeconds:600]; 
[request startAsynchronous]; 

} 
+0

を使用して、iOSの4.0および4.3のためのAVAssetをインスタンス化する具象サブクラスAVURLAssetを使用する必要がありますか?あなたはおそらく質問に答えることができるだろう:) –

+0

私はシミュレータにビデオを追加する方法を把握することができませんでした。保存した写真が画像を保存するディレクトリに置くと、UIImagePickerVirewController – Alpinista

+0

NSLog(@ "Documents:%@"、[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory、NSUserDomainMask、YES)objectAtIndex:0])には表示されません。 '多分? –

答えて

4

単純な答え:AVAssetクラスメソッド

+ (id)assetWithURL:(NSURL *)URL 

は、iOS 5.0の前には使用できません。あなたはそれがシミュレータでクラッシュしない、それがクラッシュどこで見つけることができる、そのクラスのメソッド

+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options 
関連する問題