2016-09-28 5 views
-1

Xcode 8.0プロジェクトに追加したファイル 'd.mp3'を開こうとしています。
Xcode>プロジェクト> 'd.mp3'をダブルクリックすると、ファイルは正常に再生されます。
しかし、iPhone6 +(iOS 10.0.1)でXcodeを実行すると、fopen()はファイルハンドルとして0を返します。iPhone6 +上のXcodeアプリケーションでバイナリのファイルを開くことができません

コードと次の出力...

bool read_next_chunk(char* relative_file_pathname, unsigned char* chunk_buffer, int chunk_size_bytes, FILE* file_handle ) 

{ CONSTのブールDBG = TRUE。

// Get absolute file pathname: 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask, YES); 
    NSString *program_directory = [paths objectAtIndex:0]; 
    NSString* absolute_pathname = [NSString stringWithFormat: @"%@/%s", program_directory, relative_file_pathname ]; 

if(dbg) printf("\n%s: file '%s'. Path '%s'.", __FUNCTION__, relative_file_pathname, [absolute_pathname UTF8String]); 

// Open file if not already open: 
if(file_handle == NULL) 
{ 
    if(dbg) printf("\n%s Open file %s.", __FUNCTION__, relative_file_pathname); 
    file_handle = fopen([absolute_pathname UTF8String], "rb");   // open for binary reading 
    if(dbg) printf("\n%s file_handle %d.", __FUNCTION__, file_handle); 
} 
if(file_handle) 
{ 
    // Read next chunk of file into file_content_string: 
    int total_read_bytes = (int)fread(chunk_buffer, 1, chunk_size_bytes, file_handle); 
    if(total_read_bytes != chunk_size_bytes) 
    { 
     printf("\n %s: %d total_read_bytes != %d chunk_size_bytes -- FAULT!! <<<<<<<<<<<",__FUNCTION__, total_read_bytes, chunk_size_bytes); 
     return false; 
    } 
    return true; 
} 
else 
{ 
    printf("\ %s: Cannot open '%s' FAULT!! <<<<<<<<<<<", __FUNCTION__, relative_file_pathname); 
    return false; 
} 

}

read_next_chunk:ファイル 'd.mp3'。パス '/var/mobile/Containers/Data/Application/C8B87C49-C6CF-4677-B775-6B3DF6EFD908/Documents/d.mp3'に移動します。
read_next_chunkファイルd.mp3を開きます。
read_next_chunk file_handle 0. read_next_chunk: 'd.mp3'を開くことができませんFAULT !! < < < < < < < < < < <

+0

ファイルがアプリケーションにバンドルされている場合、そのファイルはドキュメントフォルダにありません。 'NSBundle'を使ってそれにアクセスしてください。 – rmaddy

答えて

1

rmaddyが言ったように、それはあなたのドキュメントディレクトリにありそうではありません。

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"d" ofType:@"mp3"]; 
関連する問題