English 中文(简体)
MPMoviePlayerController with no content (iOS 5) - The Action Not Be Availabled
原标题:MPMoviePlayerController with no content (iOS 5) - The Operation Could Not Be Completed

我对<代码>MPMoviePlayerController有问题( un.mp)。 当我想查阅<代码>duration property时,我收到0,当时我想要查阅thumbnail......,我收到<编码>nil。 关于4号SOS,它不是科索沃。

After all app says to me: The Operation Could Not Be Completed.

- (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_%.0f@2x.%@", 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];
}

www.un.org/Depts/DGACM/index_spanish.htm 更简单的例子

I am doing this:

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

www.un.org/Depts/DGACM/index_french.htm 之后,我设立了<代码>MPMoviePlayerController。 例如:

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

But self.mp give me no content. When I want to do [self.mp duration], it returns zero/nil. Path to resource works, but it seems no content is there.

感谢您的帮助。

最佳回答

I figured out my problem. It is like iOS5 is not comfortable with:

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

相反,如果你刚才使用,

NSURL *someUrl =[info objectForKey:UIImagePickerControllerMediaURL] ;

and then initial mpmovieplayercontroller with this url, it works fine for me, which is exactly the opposite of 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];   


}
问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签