質問編集履歴

2

誤字の修正

2015/02/08 14:06

投稿

saikoro
saikoro

スコア10

test CHANGED
File without changes
test CHANGED
@@ -22,7 +22,9 @@
22
22
 
23
23
  NSString *pth01 = [bnd01 pathForResource:@"ongen0"
24
24
 
25
+ ofType:@"mp3"];
26
+
25
- ofType:@"mp3"];*url01 = [NSURL fileURLWithPath:pth01];
27
+ NSURL *url01 = [NSURL fileURLWithPath:pth01];
26
28
 
27
29
 
28
30
 
@@ -68,6 +70,8 @@
68
70
 
69
71
  ```
70
72
 
73
+ で済むのですが、音源をキーから引用して準備する方法がわかりません。
74
+
71
75
  以上、どなたかご教示いただけないでしょうか。
72
76
 
73
77
  何卒よろしくお願いいたします

1

画像の追加など

2015/02/08 14:06

投稿

saikoro
saikoro

スコア10

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