2011-10-14 12 views
1

MPMoviePlayerControllerself.mp)に問題があります。 durationのプロパティにアクセスしたい場合は0thumbnail…にアクセスするときはnilとなります。 iOS 4では正常ですが、iOS 5ではありません。コンテンツのないMPMoviePlayerController(iOS 5) - 操作を完了できませんでした

すべてのアプリが私に言うと:操作は完了できませんでした。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
    if([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie]){ 
     NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 


     NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
     double hashToNameOfFile = [NSDate timeIntervalSinceReferenceDate] * 1000.0; 
     NSString *finalPath = [rootPath stringByAppendingPathComponent:[NSString stringWithFormat: @"%.0f.%@", hashToNameOfFile, @"MOV"]]; 
     NSString *finalPathToThumbRetina = [rootPath stringByAppendingPathComponent:[NSString stringWithFormat: @"thumb_%[email protected]%@", hashToNameOfFile, @"jpg"]]; 
     NSString *finalPathToThumb = [rootPath stringByAppendingPathComponent:[NSString stringWithFormat: @"thumb_%.0f.%@", hashToNameOfFile, @"jpg"]]; 

     // we do need retina now, we use real name for CoreData 
     NSString *finalImage = [finalPath lastPathComponent]; 
     NSString *finalImageThumb = [finalPathToThumb lastPathComponent]; 


     if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(tempFilePath)){ 
      // Copy it to the camera roll. 
      UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, @selector(video:didFinishSavingWithError:contextInfo:), tempFilePath); 
     } 

     // save video to application directory 
     NSData *videoData = [NSData dataWithContentsOfFile:tempFilePath]; 
     if ([videoData writeToFile:finalPath atomically:YES]) { 
      NSLog(@"SAVED"); 
     } 
     else{ 
      NSLog(@"NOT SAVED"); 
     } 


     // create thumbnail of video 
     MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalPath]]; 
     self.mp = moviePlayer; 
     [moviePlayer release]; 

     NSData *videoData2 = [NSData dataWithContentsOfFile:finalPath]; 
     NSLog(@"LENGTH %i", [videoData2 length]); 


     NSLog(@"FINAL PATH %@", finalPath); 
     UIImage *image = [[[UIImage alloc] init] autorelease]; 
     image = [self.mp thumbnailImageAtTime:(NSTimeInterval)1.0 timeOption:MPMovieTimeOptionNearestKeyFrame]; 
     NSLog(@"%@", [image size]); 
     UIImage *thumbImageRetina = [image thumbnailImage:400 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationDefault]; 
     UIImage *thumbImage = [image thumbnailImage:200 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationDefault]; 
     NSData *thumbImageRetinaData = [NSData dataWithData:UIImageJPEGRepresentation(thumbImageRetina, 1.0)]; 
     NSData *thumbImageData = [NSData dataWithData:UIImageJPEGRepresentation(thumbImage, 1.0)]; 
     if ([thumbImageRetinaData writeToFile:finalPathToThumbRetina atomically:YES]) { 
      NSLog(@"RETINA THUMB SAVED"); 
     } 
     else{ 
      NSLog(@"RETINA THUMB NOT SAVED"); 
     } 
     if ([thumbImageData writeToFile:finalPathToThumb atomically:YES]) { 
      NSLog(@"THUMB SAVED"); 
     } 
     else{ 
      NSLog(@"THUMB NOT SAVED"); 
     } 

     // duration of video 
     double dur = [self.mp duration]; 
     NSLog(@"DUR %f", dur); 


     TaleRecords *newTaleRecord = (TaleRecords *)[NSEntityDescription insertNewObjectForEntityForName:@"TaleRecords" inManagedObjectContext:_context]; 

     newTaleRecord.content = finalImage; 
     newTaleRecord.date = [NSDate date]; 
     NSDecimalNumber *latNum = [[NSDecimalNumber alloc] initWithDouble:[self.latitude doubleValue]]; 
     NSDecimalNumber *longNum = [[NSDecimalNumber alloc] initWithDouble:[self.longitude doubleValue]]; 
     newTaleRecord.latitude = latNum; // vertical 
     newTaleRecord.longitude = longNum; // horizontal 
     [latNum release]; 
     [longNum release]; 
     newTaleRecord.contentType = [[NSString alloc] initWithFormat:@"cTypeVideo"]; 
     newTaleRecord.thumb = finalImageThumb; 
     newTaleRecord.duration = [NSNumber numberWithDouble:dur]; 

     newTaleRecord.tale = tales; 
     tales.record = [newTaleRecord tale].record; 

     NSError *error = nil; 
     if (![_context save:&error]) { 
      /* 
      Replace this implementation with code to handle the error appropriately. 

      abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 
      */ 
      NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
      abort(); 
     } 
    } 


    [CLController.locationManager stopUpdatingLocation]; 
    [self dismissModalViewControllerAnimated:YES]; 
} 

私はこれをやっている

もっと簡単な例:tempFilePath

// save video to application directory 
NSData *videoData = [NSData dataWithContentsOfFile:tempFilePath]; 
if ([videoData writeToFile:finalPath atomically:YES]) { 
    NSLog(@"SAVED"); 
} 
else{ 
    NSLog(@"NOT SAVED"); 
} 

は、実際の映像コンテンツであると私はfinalPathに書き込みます。

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalPath]]; 
self.mp = moviePlayer; 
[moviePlayer release]; 

しかしself.mpは私に何のコンテンツを与えない:その後、私はMPMoviePlayerControllerインスタンスを作成します。 [self.mp duration]を実行する場合は、zero/nilを返します。リソースへのパスは機能しますが、コンテンツは存在しないようです。

ありがとうございました。

+0

...同様にあなたを助けるかもしれない:

は、ここに私のコードです! –

+0

OK、**もっと簡単な例**を追加しました。 – petesalt

答えて

3

私は私の問題を理解しました。 それはiOS5をのようなものに慣れていないです:あなたはちょうど

NSURL *someUrl =[info objectForKey:UIImagePickerControllerMediaURL] ; 

、次のURLで、初期mpmovieplayercontrollerを使用している場合は、その代わりに

NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; 

、それは正確である 、私のために正常に動作しますiOS4の反対側。

あなたはもっと簡単な例を提供する場合、それは間違いなく役立つだろう
- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 



    mediaURL = [info objectForKey:UIImagePickerControllerMediaURL]; 
    NSLog(@"%@",mediaURL); 
    if (!mymoviePlayer) { 
     mymoviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:mediaURL]; 
     [mymoviePlayer setControlStyle:MPMovieControlStyleNone]; 
     [mymoviePlayer.view setFrame: videoView.bounds]; 
     [videoView addSubview:mymoviePlayer.view]; 
    } 
    else 
    { 

     [mymoviePlayer setContentURL:mediaURL]; 
     [mymoviePlayer stop]; 
     [mymoviePlayer setInitialPlaybackTime:-1]; 
    } 

[self dismissModalViewControllerAnimated:YES]; 


} 
+0

ありがとうございました。これは私が必要とするものです。私はiOS5でビデオに他の問題を抱えていますが、これが最大です。ありがとうございました。 – petesalt

+1

Argh!あなたと同じ問題を抱えていて、MPMoviePlayerControllerがシステムによって有効なオブジェクトとみなされていても、特定のNSURLが好きではないことを理解するために私は年齢を取っていました。 "秘密"はファイルパスをNSStringとして取得し、 '[NSURL fileURLWithPath:URLStringPath]'を使用することです。 – Rog

+0

Rogのコメントは正確な答えです。 –

関連する問題