2010-03-25 113 views
-1

我試圖在資源文件夾中獲得10個mp3文件,並在按下按鈕時播放它們。我已經在一個NSMutableArray中輸入了mp3文件的名稱,並且在按下按鈕之後讀取每個文件的名稱。Iphone SDK:pathFoResource:Nsstring問題 - >播放MP3文件

問題是,pathForResource:不起作用(返回nil)。如果我使用的文件名明確般pathFoResource:@「song1.mp3」 ofType:@「MP3」 - 但如果我使用pathForResource:值M whwre值M是一個NSString與鬆1的值

希望你能幫助

問候

NSString *cellValue0 = [listOfmp3 objectAtIndex:anumber]; 
NSString *valuem; 

if ([cellValue0 length] > 0) 
    valuem = [cellValue0 substringToIndex:[cellValue0 length] - 4]; 


NSString *pdfPath2 = [[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"]; 
NSURL *url = [NSURL fileURLWithPath:pdfPath2]; 
+0

嘗試登錄值M,以檢查其是否預期值的字符串... – Vladimir 2010-03-25 09:37:52

回答

2

不要把資源名稱的擴展,即

[bundle pathForResource:@"song1" ofType:@"mp3"]; // correct 
[bundle pathForResource:@"song1.mp3" ofType:@"mp3"]; // wrong — gets song1.mp3.mp3. 

檢查valuem不攜帶任何擴展。

0

對不起,我以前的帖子,下面是更明確的措詞重申問題:

弗拉季米爾: 是我記錄的值M和它給正確的字符串

KennyTM: 是的,是一個錯字,在原來的代碼只有@「鬆1」

的問題是, 如果我使用

[[NSBundle mainBundle] pathForResource:"song1" ofType:@"mp3"]; It is working 

但是,如果使用

[[NSBundle mainBundle] pathForResource:valuem ofType:@"mp3"]; 

它不工作 注意,值是@「鬆1」