2012-02-28 3 views
1

안녕하세요, 저는 사운드 파일을 Facebook에 업로드해야하는 응용 프로그램에서 작업하고 있습니다.iphone에서 페이스 북이나 트위터로 사운드 파일을 공유하는 방법

페이스 북에서 사운드 파일을 공유 할 수 있는지 여부에 관계없이 더 나은 해결책을 제공해주십시오.

미리 감사드립니다.

+1

http : //developers.soundcloud를 살펴보십시오.com/blog/ios-sharing – Mat

+0

@Mat, 유망 해 보입니다. 댓글 대신 답을 입력해야합니다. – picciano

답변

0

Facebook에 소리가 업로드되지 않았습니다. 언제 어디서나 사운드 파일을 업로드하고 Facebook을 사용하여 링크를 공유 할 수 있습니다.

0

트위터/페이스 북용 웹 애플리케이션을 확인하면 오디오 파일을 업로드 할 수있는 방법이 없습니다.

Twittier는 텍스트 게시 만 허용하고 반면 Facebook은 이미지/비디오 업로드를 허용합니다.

이러한 사실에 비추어 볼 때 나는 URL 공유가 없다면 불가능하다고 생각합니다.

0

오디오 파일을 Facebook에 업로드 할 수 없으며 사진과 비디오 만 허용됩니다. 그러나 또 다른 해결책은 다른 곳에서 오디오 파일을 업로드 한 다음 Facebook API를 사용하여 해당 참조를 사용하여 링크를 게시하는 것입니다. 오디오 업로드를 원할 수도있는 곳은 http://developers.soundcloud.com/

0

AVAssetExportSession을 사용하여 사운드 파일로 동영상을 만든 다음 Facebook에 업로드하십시오.

0

이것은 가능하지만 약간의 고통입니다. 이렇게하려면 오디오 파일을 비디오 파일로 변환 한 다음 비디오로 Facebook에 게시해야합니다.

먼저 우리는 audioFile에 액세스해야합니다. 이미이 파일을 가지고 있어야합니다. 그렇다면 여기에 많은 Stackoverflow 관련 질문이 있습니다. 트랙을 벗어나서 문제를 복잡하게하지 않을 것입니다. 그런 다음 우리 문서의 비디오에 대한 NSURL을 만듭니다. 이 경우 우리는 audio_base.mp4라는 이름의 비디오를 가지고 있습니다.이 비디오는 오디오 트랙의 멋진 배경으로 설계되었습니다. 마지막으로 Facebook에 반환 된 파일을 공유하기 전에 파일을 병합합니다.

- (IBAction)shareToFacebook:(id)sender { 

    // You should already have your audio file saved 
    NSString * songFileName = [self getSongFileName]; 

    NSArray * searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString * documentPath = [searchPaths objectAtIndex:0]; 

    NSString * file = [documentPath stringByAppendingPathComponent:songFileName]; 
    NSURL * audioFileURL = [NSURL fileURLWithPath: audioFile]; 
    NSURL * videoFileURL = [NSURL fileURLWithPath:[NSFileManager getFilePath:@"video_base.mp4" withFolder:@""]]; 

    [self mergeAudio:audioFileURL andVideo:videoFileURL withSuccess:^(NSURL * url) { 

     // Now we have the URL of the video file 
     [self shareVideoToFacebook:url]; 
    }]; 
} 

신용 here을 찾을 수있는 코드의이 부분에 대한 @dineshprasanna합니다. 우리는 오디오와 비디오를 병합 한 다음 경로에 저장하려고합니다. 그런 다음 완료 블록에서 exportURL을 반환합니다.

- (void)mergeAudio: (NSURL *)audioURL andVideo: (NSURL *)videoURL withSuccess:(void (^)(NSURL * url))successBlock { 

    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil]; 
    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoURL options:nil]; 

    AVMutableComposition * mixComposition = [AVMutableComposition composition]; 

    AVMutableCompositionTrack * compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio 
                        preferredTrackID:kCMPersistentTrackID_Invalid]; 
    [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, audioAsset.duration) 
            ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
            atTime:kCMTimeZero error:nil]; 

    AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                       preferredTrackID:kCMPersistentTrackID_Invalid]; 
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) 
           ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
           atTime:kCMTimeZero error:nil]; 

    AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition 
                     presetName:AVAssetExportPresetHighestQuality]; 

    NSString * videoName = @"export.mov"; 

    NSString * exportPath = [NSTemporaryDirectory() stringByAppendingPathComponent:videoName]; 
    NSURL * exportUrl = [NSURL fileURLWithPath:exportPath]; 

    if ([[NSFileManager defaultManager] fileExistsAtPath:exportPath]) { 
     [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil]; 
    } 

    _assetExport.outputFileType = @"com.apple.quicktime-movie"; 
    _assetExport.outputURL = exportUrl; 
    _assetExport.shouldOptimizeForNetworkUse = YES; 

    [_assetExport exportAsynchronouslyWithCompletionHandler: ^(void) { 
     if(successBlock) successBlock(exportUrl); 
    }]; 
} 

마지막으로 우리는 return videoURL을 Facebook에 저장하려고합니다.

#import <AssetsLibrary/AssetsLibrary.h> 
#import <FBSDKCoreKit/FBSDKCoreKit.h> 
#import <FBSDKShareKit/FBSDKShareKit.h> 

우리는 다음 페이스 북에 병합 된 파일 공유 :

- (void)shareVideoToFacebook: (NSURL *)videoURL { 

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    ALAssetsLibraryWriteVideoCompletionBlock videoWriteCompletionBlock = ^(NSURL *newURL, NSError *error) { 
     if(error) { 
      NSLog(@"Error writing image with metadata to Photo Library: %@", error); 
     } else { 
      NSLog(@"Wrote image with metadata to Photo Library %@", newURL.absoluteString); 

      FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc]init]; 
      NSURL *videoURL = newURL; 

      FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init]; 
      video.videoURL = videoURL; 

      FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init]; 
      content.video = video; 

      [FBSDKShareDialog showFromViewController:self 
            withContent:content 
             delegate:nil]; 
     } 
    }; 

    if([library videoAtPathIsCompatibleWithSavedPhotosAlbum:videoURL]) { 
     [library writeVideoAtPathToSavedPhotosAlbum:videoURL 
           completionBlock:videoWriteCompletionBlock]; 
    } 
} 

이 페이스 북의 응용 프로그램을 열고해야하고 우리가이 기능이 작동하려면 몇 가지 라이브러리를 추가 할 필요가 있음을 주목할 필요가있다 그런 다음 사용자가 벽에있는 오디오 파일을 앱에 저장된 비디오의 배경과 공유 할 수 있습니다.

분명히 모든 사람의 프로젝트가 다릅니다. 즉,이 코드를 프로젝트에 정확하게 복사 할 수 없을 수도 있습니다. 오디오 메시지를 성공적으로 업로드하기 위해 외삽 법을 쉽게 이해해야한다는 의미에서 프로세스를 분리하려고했습니다.

관련 문제