2011-08-26 46 views
0

首先我是一個n00b。 經過3天的努力和研究,我決定獲得一些外部幫助。音頻本地化

我做什麼,我的項目:

我做一本書的孩子。 現在我正在本地化我的應用程序。 的圖片我沒有這樣說:

UIImage *schrift = [UIImage imageNamed:NSLocalizedString (@"Schrift_en.png", nil)]; 
image = [[UIImageView alloc] initWithImage:schrift]; 
image.frame = CGRectMake(75.5, 80, 617, 137); 
[self.view addSubview:image]; 
[image release]; 

爲我的偉大工程:)

現在我試圖做同樣的我講述AUDIOFILE但不容弄清楚如何。

NSString *path = [[NSBundle mainBundle] pathForResource:@"Vorwort" ofType:@"mp3"]; 
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
self.audioPlayer = theAudio; 
[theAudio release]; 

如何更改上面的代碼,使其工作,以及如何定義ofType:@在Localizable.strings文件「MP3」?

Google無法幫助我。 任何想法?慢慢地,但肯定我失去了我的動力。

如果有人能幫助我,這將會非常酷! 在此先感謝 Planky

回答

2

試試這個

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], NSLocalizedString (@"audiofilename.mp3", nil)]]; 

AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL]; 
self.audioPlayer = theAudio; 
[theAudio release]; 
+0

謝謝,很好! – Planky

3

這是不是真的有什麼Localizable.strings是。檢查出一個NSBundle的pathForResource:ofType:

方法的文檔首先會在指定捆綁的非本地化資源目錄匹配的資源文件。 (...在iOS中,它是主包目錄。)如果未找到匹配的資源文件,它將查找任何可用的特定於語言的「.lproj」目錄的頂層。 (特定於語言的目錄的搜索順序與用戶的首選項相對應。)它不通過其他任何位置的子目錄進行遞歸。

所以,如果你以前有你的音頻文件在這裏:

YourBook.app/Vorwort.mp3 

則應該安排這樣的:

YourBook.app/en.lproj/Vorwort.mp3 
YourBook.app/fr.lproj/Vorwort.mp3 

沒有Volwort.mp3應的頂級存在.app文件夾。

您將需要創建en.lroj/fr.lproj目錄並將它們拖到您的XCode項目中。右鍵單擊Finder中的.app,然後單擊「顯示捆綁軟件內容」,檢查您的應用程序捆綁結構。