簡體   English   中英

視頻應用程序將.mp4保存到相機膠卷

[英]video app save .mp4 to camera roll

我有一個vidoe應用程序,她所做的就是播放一個.mp4文件。 我想將該文件保存到iPhone的相機膠卷中,然后將其播放。 我已經有了代碼,但是由於某種原因,視頻無法保存。

沒有錯誤,似乎沒有放錯任何地方,但仍然無法保存。 我花了幾個小時來解決這個問題,但沒有成功。 是否有人可以幫助我解決? 請? 漂亮嗎? 這是保存功能的代碼...

- (IBAction)save{

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    // don't forget to link to the AssetsLibrary framework
    // and also #import <AssetsLibrary/AssetsLibrary.h>

    NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"];
    NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO];

    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:filePathURL]) {
        [library writeVideoAtPathToSavedPhotosAlbum:filePathURL completionBlock:^(NSURL *assetURL, NSError *error){
            if (error) {
               // TODO: error handling

            } else {
                // TODO: success handling
            }
        }];
    }
    }

抱歉,沒有人回答這個問題。 如果您仍然需要幫助,這應該為您工作:

- (IBAction)save{
    NSString *filePathString = [[NSBundle mainBundle] pathForResource:@"video_name" ofType:@"mp4"];
    NSURL *filePathURL = [NSURL fileURLWithPath:filePathString isDirectory:NO];

    UISaveVideoAtPathToSavedPhotosAlbum([filePathURL relativePath], self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}

- (void) video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    if (!error){
        // Saved successfully
    } else {
        // Error saving
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM