統計
| ブランチ: | リビジョン:

pictcode / app / webroot / js / pictcode / sound_manager.js @ 0b1b8047

履歴 | 表示 | アノテート | ダウンロード (7.652 KB)

1
define(["utility"], function(utility){
2

    
3
  //----------------サウンド----------------//
4
  var soundInfos = [
5
  //SE
6
  {name:"ACTION1", ext:"mp3", category:"se", soundKey:0},
7
  {name:"ACTION2", ext:"mp3", category:"se", soundKey:1},
8
  {name:"ACTION3", ext:"mp3", category:"se", soundKey:2},
9
  {name:"ACTION4", ext:"mp3", category:"se", soundKey:3},
10
  {name:"ACTION5", ext:"mp3", category:"se", soundKey:4},
11
  {name:"ACTION6", ext:"mp3", category:"se", soundKey:5},
12
  {name:"ACTION7", ext:"mp3", category:"se", soundKey:6},
13
  {name:"ACTION8", ext:"mp3", category:"se", soundKey:7},
14
  {name:"ACTION9", ext:"mp3", category:"se", soundKey:8},
15
  {name:"ACTION10", ext:"mp3", category:"se", soundKey:9},
16
  {name:"AIRPLANE1", ext:"mp3", category:"se", soundKey:10},
17
  {name:"AIRPLANE2", ext:"mp3", category:"se", soundKey:11},
18
  {name:"ALERT1", ext:"mp3", category:"se", soundKey:12},
19
  {name:"ALERT2", ext:"mp3", category:"se", soundKey:13},
20
  {name:"ALERT3", ext:"mp3", category:"se", soundKey:14},
21
  {name:"ALERT4", ext:"mp3", category:"se", soundKey:15},
22
  {name:"ALERT5", ext:"mp3", category:"se", soundKey:16},
23
  {name:"ATTACK1", ext:"mp3", category:"se", soundKey:17},
24
  {name:"ATTACK2", ext:"mp3", category:"se", soundKey:18},
25
  {name:"ATTACK3", ext:"mp3", category:"se", soundKey:19},
26
  {name:"ATTACK4", ext:"mp3", category:"se", soundKey:20},
27
  {name:"ATTACK5", ext:"mp3", category:"se", soundKey:21},
28
  {name:"ATTACK6", ext:"mp3", category:"se", soundKey:22},
29
  {name:"ATTACK7", ext:"mp3", category:"se", soundKey:23},
30
  {name:"ATTACK8", ext:"mp3", category:"se", soundKey:24},
31
  {name:"ATTACK9", ext:"mp3", category:"se", soundKey:25},
32
  {name:"ATTACK10", ext:"mp3", category:"se", soundKey:26},
33
  {name:"ATTACK11", ext:"mp3", category:"se", soundKey:27},
34
  {name:"ATTACK12", ext:"mp3", category:"se", soundKey:28},
35
  {name:"ATTACK13", ext:"mp3", category:"se", soundKey:29},
36
  {name:"ATTACK14", ext:"mp3", category:"se", soundKey:30},
37
  {name:"BOAT1", ext:"mp3", category:"se", soundKey:31},
38
  {name:"BOAT2", ext:"mp3", category:"se", soundKey:32},
39
  {name:"BUS1", ext:"mp3", category:"se", soundKey:33},
40
  {name:"BYCICLE1", ext:"mp3", category:"se", soundKey:34},
41
  {name:"BYCICLE2", ext:"mp3", category:"se", soundKey:35},
42
  {name:"CAR1", ext:"mp3", category:"se", soundKey:36},
43
  {name:"CAR2", ext:"mp3", category:"se", soundKey:37},
44
  {name:"CAR3", ext:"mp3", category:"se", soundKey:38},  
45
  {name:"CAR4", ext:"mp3", category:"se", soundKey:39},
46
  {name:"CAR5", ext:"mp3", category:"se", soundKey:40}, 
47
  {name:"CAR6", ext:"mp3", category:"se", soundKey:41},
48
  {name:"CAT1", ext:"mp3", category:"se", soundKey:42}, 
49
  {name:"CAT2", ext:"mp3", category:"se", soundKey:43},
50
  {name:"CAT3", ext:"mp3", category:"se", soundKey:44},
51
  {name:"CHEER1", ext:"mp3", category:"se", soundKey:45},
52
  {name:"CHEER2", ext:"mp3", category:"se", soundKey:46},
53
  {name:"CHEER3", ext:"mp3", category:"se", soundKey:47},
54
  {name:"CHIME1", ext:"mp3", category:"se", soundKey:48},
55
  {name:"CHIME2", ext:"mp3", category:"se", soundKey:49},
56
  {name:"CHIME3", ext:"mp3", category:"se", soundKey:50},
57
  {name:"CHIME4", ext:"mp3", category:"se", soundKey:51},
58
  {name:"CHIME5", ext:"mp3", category:"se", soundKey:52},
59
  {name:"CHIME6", ext:"mp3", category:"se", soundKey:53},
60
  {name:"CHIME7", ext:"mp3", category:"se", soundKey:54},
61
  {name:"CHIME8", ext:"mp3", category:"se", soundKey:55},
62
  {name:"CORRECT1", ext:"mp3", category:"se", soundKey:56},
63
  {name:"DOG1", ext:"mp3", category:"se", soundKey:57},
64
  {name:"DOG2", ext:"mp3", category:"se", soundKey:58},
65
  {name:"DRUM1", ext:"mp3", category:"se", soundKey:59},
66
  {name:"DRUM2", ext:"mp3", category:"se", soundKey:60},
67
  {name:"DRUM3", ext:"mp3", category:"se", soundKey:61},
68
  {name:"DRUM4", ext:"mp3", category:"se", soundKey:62},
69
  {name:"FALLING1", ext:"mp3", category:"se", soundKey:63},
70
  {name:"FALLING2", ext:"mp3", category:"se", soundKey:64},
71
  {name:"FALLING3", ext:"mp3", category:"se", soundKey:65},
72
  {name:"FIRE1", ext:"mp3", category:"se", soundKey:66},
73
  {name:"FIRE2", ext:"mp3", category:"se", soundKey:67},
74
  {name:"HORN1", ext:"mp3", category:"se", soundKey:68},
75
  {name:"PIANO1", ext:"mp3", category:"se", soundKey:69},
76
  {name:"PIANO2", ext:"mp3", category:"se", soundKey:70},
77
  {name:"PIANO3", ext:"mp3", category:"se", soundKey:71},
78
  {name:"PIANO4", ext:"mp3", category:"se", soundKey:72},
79
  {name:"PIANO5", ext:"mp3", category:"se", soundKey:73},
80
  {name:"PIANO6", ext:"mp3", category:"se", soundKey:74},
81
  {name:"PIANO7", ext:"mp3", category:"se", soundKey:75},
82
  {name:"PIANO8", ext:"mp3", category:"se", soundKey:76},
83
  {name:"QUESTION1", ext:"mp3", category:"se", soundKey:77},
84
  {name:"QUESTION2", ext:"mp3", category:"se", soundKey:78},
85
  {name:"QUESTION3", ext:"mp3", category:"se", soundKey:79},
86
  {name:"QUESTION4", ext:"mp3", category:"se", soundKey:80},
87
  {name:"SIREN1", ext:"mp3", category:"se", soundKey:81},
88
  {name:"START1", ext:"mp3", category:"se", soundKey:82},
89
  {name:"START2", ext:"mp3", category:"se", soundKey:83},
90
  {name:"SWING1", ext:"mp3", category:"se", soundKey:84},
91
  {name:"SWING2", ext:"mp3", category:"se", soundKey:85},
92
  {name:"SWING3", ext:"mp3", category:"se", soundKey:86},
93
  {name:"WATER1", ext:"mp3", category:"se", soundKey:87},
94
  
95
  //BGM
96
  {name:"BOSSA1", ext:"wav", category:"bgm", soundKey:1000},
97
  {name:"FANTASY1", ext:"wav", category:"bgm", soundKey:1001},
98
  {name:"FANTASY2", ext:"wav", category:"bgm", soundKey:1002},
99
  {name:"FANTASY3", ext:"wav", category:"bgm", soundKey:1003},
100
  {name:"FANTASY4", ext:"wav", category:"bgm", soundKey:1004},
101
  {name:"ORCHESTRA1", ext:"wav", category:"bgm", soundKey:1005},
102
  {name:"POP1", ext:"wav", category:"bgm", soundKey:1006},
103
  {name:"POP2", ext:"wav", category:"bgm", soundKey:1007},
104
  {name:"POP3", ext:"wav", category:"bgm", soundKey:1008},
105
  {name:"POP4", ext:"wav", category:"bgm", soundKey:1009},
106
  {name:"ROCK1", ext:"wav", category:"bgm", soundKey:1010},
107
  {name:"ROCK2", ext:"wav", category:"bgm", soundKey:1011},
108
  {name:"ROCK3", ext:"wav", category:"bgm", soundKey:1012},
109

    
110
  ];
111

    
112
  function findSoundInfoFromImageKey(soundKey){
113
    var soundInfo = _.find(soundInfos, function(soundInfo){
114
      return soundInfo.soundKey == soundKey;
115
    });
116
    return soundInfo;
117
  }
118

    
119
  function getCategorizedSoundInfos(category){
120
    var categorizedSoundInfos = [];
121
    _.each(soundInfos, function(soundInfo){
122
      if (soundInfo.category == category) {
123
        categorizedSoundInfos.push(soundInfo);
124
      };
125
    });
126
    return categorizedSoundInfos;
127
  }
128

    
129
  //----------------カテゴリ----------------//
130
  var categoryInfos =[
131
  {name: "se", imageKey: "sound_001"},
132
  {name: "bgm", imageKey: "sound_002"},
133
  ];
134

    
135
  //----------------再生----------------//
136
  function playSound(soundKey, isRepeat){
137
    var audio = loadSound(soundKey);
138
    if (!audio) {return};
139
    audio.pause();
140
    audio.currentTime = 0;
141
    if (isRepeat) {
142
      audio.loop = true;
143
    }else{
144
      audio.loop = false;
145
    };
146
    audio.play();
147
  }
148

    
149
  function loadSound(soundKey){
150
    var soundInfo = findSoundInfoFromImageKey(soundKey);
151
    if (!soundInfo ) {return null;};
152
    if (soundInfo.audio) {return soundInfo.audio;};
153
    var path = "sound/" + soundInfo.category + "/" + soundInfo.name + "." + soundInfo.ext;
154
    var audio = new Audio(path);
155
    soundInfo.audio = audio;
156
    return audio;
157
  }
158

    
159
  function stopAllSound(){
160
    _.each(soundInfos, function(soundInfo){
161
      if (soundInfo.audio) {
162
        soundInfo.audio.pause();
163
        soundInfo.audio.currentTime = 0;
164
      };
165
    });
166
  }
167

    
168
  //----------------プリロード----------------//
169

    
170

    
171
  return {
172
    findSoundInfoFromImageKey:findSoundInfoFromImageKey,
173
    getCategorizedSoundInfos:getCategorizedSoundInfos,
174
    categoryInfos:categoryInfos,
175
    playSound:playSound,
176
    loadSound:loadSound,
177
    stopAllSound:stopAllSound,
178
  };
179
});