teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

誤字の修正

2015/02/08 14:06

投稿

saikoro
saikoro

スコア10

title CHANGED
File without changes
body CHANGED
@@ -10,7 +10,8 @@
10
10
  // 音楽ファイル参照
11
11
  NSBundle *bnd01 = [NSBundle mainBundle];
12
12
  NSString *pth01 = [bnd01 pathForResource:@"ongen0"
13
+ ofType:@"mp3"];
13
- ofType:@"mp3"];*url01 = [NSURL fileURLWithPath:pth01];
14
+ NSURL *url01 = [NSURL fileURLWithPath:pth01];
14
15
 
15
16
  // AVAudioPlayerオブジェクト生成
16
17
  _adp01 = [[AVAudioPlayer alloc] initWithContentsOfURL:url01
@@ -33,5 +34,6 @@
33
34
  NSString *aaa=[[NSString alloc] initWithFormat:@"タイトル%lu",(unsigned long)_rowNumber];
34
35
  _label.text = [listDict valueForKey:aaa];
35
36
  ```
37
+ で済むのですが、音源をキーから引用して準備する方法がわかりません。
36
38
  以上、どなたかご教示いただけないでしょうか。
37
39
  何卒よろしくお願いいたします

1

画像の追加など

2015/02/08 14:06

投稿

saikoro
saikoro

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,19 +1,37 @@
1
1
  xcodeでplistのキーから音源を再生させるにはどうすればいいのでしょう?
2
- AudioServicesCreateSystemSoundIDを使いたいのですが、
2
+ AVAudioPlayerを使いたいのですが、キーを音源再生のコードのどこにどう
3
- キーを音源再生のコードのどこにどう割りこませればいいのかがわかりません。
3
+ 割りこませればいいのかがわかりません。あるViewController上に、
4
+ 添付画像のようなplist(名前:photo0)の中身であるテキスト・画像・音源データを
5
+ 準備したいのです。
6
+ ![イメージ説明][WIDTH:600](70f2857d555bfe4a03c33bdaf0ca1e9f.jpeg)
7
+
4
8
  音源の設定には以下のコードを使用します。
5
9
  ```
10
+ // 音楽ファイル参照
11
+ NSBundle *bnd01 = [NSBundle mainBundle];
12
+ NSString *pth01 = [bnd01 pathForResource:@"ongen0"
13
+ ofType:@"mp3"];*url01 = [NSURL fileURLWithPath:pth01];
6
14
 
7
- // バンドル参照(共通)
15
+ // AVAudioPlayerオブジェクト生成
8
- NSBundle *bnd = [NSBundle mainBundle];// バンドル内を参照できるようにした。
16
+ _adp01 = [[AVAudioPlayer alloc] initWithContentsOfURL:url01
17
+ error:nil];
18
+ ```
9
19
 
10
- // 効果音1設定 バンドル内の音をファイル内で参照できるようにした。
11
- // _rowNumberは、他のクラスから引っ張ってきた数値です
12
- NSString *oto=[[NSString alloc] initWithFormat:@"ongen%lu",(unsigned long)_rowNumber];
13
- NSURL *url01 =[bnd URLForResource:oto
14
- withExtension:@"mp3"];
20
+ ただ単にラベルに文字を出すだけならば
15
- CFURLRef urr01 = (CFURLRef) CFBridgingRetain(url01);// キャストさせる
21
+
16
- AudioServicesCreateSystemSoundID(urr01, &_ssId01);// オブジェクト作成
17
22
  ```
23
+ NSString* pth = [[NSBundle mainBundle]pathForResource:@"photo0"
24
+ ofType:@"plist"];
25
+
26
+ // 読み込んだplistを元に、Arrayを作る
27
+ arrayList = [NSArray arrayWithContentsOfFile:pth];
28
+
29
+ // _rowNumberは、前のクラスでタップしたTableViewCellのインデックスです
30
+ NSDictionary *listDict = [arrayList objectAtIndex:_rowNumber];
31
+
32
+ // 文章キーコメントをラベルに表示する。タップしたセルの番号がキーに反映される
33
+ NSString *aaa=[[NSString alloc] initWithFormat:@"タイトル%lu",(unsigned long)_rowNumber];
34
+ _label.text = [listDict valueForKey:aaa];
35
+ ```
18
36
  以上、どなたかご教示いただけないでしょうか。
19
37
  何卒よろしくお願いいたします