开发者

Localization of Audio

First of all i am a n00b. After 3 days of trying and research i decided to get some external help.

What i did and my Project:

i make a book for children. Now i am localizing my app. for a Image i did it like this:

UIImage *schrift = [UIImage imageNamed:NSLocalizedSt开发者_JS百科ring (@"Schrift_en.png", nil)];
image = [[UIImageView alloc] initWithImage:schrift];
image.frame = CGRectMake(75.5, 80, 617, 137);
[self.view addSubview:image];
[image release];

works great for me :)

Now i am trying to do the same with my Narrator Audiofile but can´t figure out how.

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

How can i change the code above to make it work and how to define ofType:@"mp3" in Localizable.strings-file?

Google can´t help me. Any ideas? slowly but surely i am losing my motivation.

It would be really cool if anyone could help me! Thanks in advance Planky


This isn't really what Localizable.strings is for. Check out the docs for NSBundle's pathForResource:ofType:

The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. (… in iOS, it is the main bundle directory.) If a matching resource file is not found, it then looks in the top level of any available language-specific “.lproj” directories. (The search order for the language-specific directories corresponds to the user’s preferences.) It does not recurse through other subdirectories at any of these locations.

So if you previously had your audio file here:

YourBook.app/Vorwort.mp3

you should instead arrange it like this:

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

No Volwort.mp3 should exists at the top level of the .app folder.

You will need to create the en.lroj/fr.lproj directories and drag them to your XCode project. Check your app bundle structure by right clicking on the .app in the Finder and clicking 'Show bundle contents'.


Try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜