質問編集履歴

2

MainScene\.cppのソースと、エラー該当箇所を追記しました。

2017/04/18 09:53

投稿

5_m_8_r_9
5_m_8_r_9

スコア7

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,8 @@
8
8
 
9
9
 
10
10
 
11
+ console欄エラーメッセージ
12
+
11
13
  ```
12
14
 
13
15
  E/Cocos2dxSound: error:
@@ -40,14 +42,336 @@
40
42
 
41
43
 
42
44
 
45
+ MainScene.cpp
46
+
47
+ ```C++
48
+
49
+ #include "MainScene.h"
50
+
51
+ #include "SimpleAudioEngine.h"
52
+
53
+
54
+
55
+ USING_NS_CC;
56
+
57
+
58
+
59
+ MainScene::MainScene() {
60
+
61
+ }
62
+
63
+
64
+
65
+ MainScene::~MainScene() {
66
+
67
+ }
68
+
69
+
70
+
71
+ Scene* MainScene::createScene() {
72
+
73
+ auto scene = Scene::create();
74
+
75
+ auto layer = MainScene::create();
76
+
77
+ scene->addChild(layer);
78
+
79
+ return scene;
80
+
81
+ }
82
+
83
+
84
+
85
+ bool MainScene::init() {
86
+
87
+ if ( !Layer::init() ) {
88
+
89
+ return false;
90
+
91
+ }
92
+
93
+ CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("main.mp3");
94
+
95
+
96
+
97
+ return true;
98
+
99
+ }
100
+
101
+
102
+
103
+ void MainScene::onEnter() {
104
+
105
+ Layer::onEnter();
106
+
107
+ }
108
+
109
+
110
+
111
+ void MainScene::onEnterTransitionDidFinish() {
112
+
113
+ Layer::onEnterTransitionDidFinish();
114
+
115
+
116
+
117
+ CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("main.mp3", true);
118
+
119
+ }
120
+
121
+ ```
122
+
123
+
124
+
125
+
126
+
127
+ Cocos2dxSound.java エラー付近(108,149,282)
128
+
129
+ ```
130
+
131
+ //(略)
132
+
133
+
134
+
135
+ public int preloadEffect(final String path) {
136
+
137
+ if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
138
+
139
+ CocosPlayClient.updateAssets(path);
140
+
141
+ }
142
+
143
+ CocosPlayClient.notifyFileLoaded(path);
144
+
145
+ Integer soundID = this.mPathSoundIDMap.get(path);
146
+
147
+
148
+
149
+ if (soundID == null) {
150
+
151
+ soundID = this.createSoundIDFromAsset(path);
152
+
153
+ // save value just in case if file is really loaded
154
+
155
+ if (soundID != Cocos2dxSound.INVALID_SOUND_ID) {
156
+
157
+ this.mPathSoundIDMap.put(path, soundID);
158
+
159
+ }
160
+
161
+ }
162
+
163
+
164
+
165
+ return soundID;
166
+
167
+ }
168
+
169
+
170
+
171
+ //(略)
172
+
173
+
174
+
175
+ public int playEffect(final String path, final boolean loop, float pitch, float pan, float gain){
176
+
177
+ Integer soundID = this.mPathSoundIDMap.get(path);
178
+
179
+ int streamID = Cocos2dxSound.INVALID_STREAM_ID;
180
+
181
+
182
+
183
+ if (soundID != null) {
184
+
185
+ // parameters; pan = -1 for left channel, 1 for right channel, 0 for both channels
186
+
187
+
188
+
43
- ###補足情報(言語/FW/ツール等のバージョンなど)
189
+ // play sound
190
+
191
+ streamID = this.doPlayEffect(path, soundID, loop, pitch, pan, gain);
192
+
193
+ } else {
194
+
195
+ // the effect is not prepared
196
+
197
+ soundID = this.preloadEffect(path);
198
+
199
+ if (soundID == Cocos2dxSound.INVALID_SOUND_ID) {
200
+
201
+ // can not preload effect
202
+
203
+ return Cocos2dxSound.INVALID_SOUND_ID;
204
+
205
+ }
206
+
207
+
208
+
209
+ SoundInfoForLoadedCompleted info = new SoundInfoForLoadedCompleted(path, loop, pitch, pan, gain);
210
+
211
+ mPlayWhenLoadedEffects.putIfAbsent(soundID, info);
212
+
213
+
214
+
215
+ synchronized(info) {
216
+
217
+ try {
218
+
219
+ info.wait(LOAD_TIME_OUT);
220
+
221
+ }
222
+
223
+ catch (Exception e) {
224
+
225
+ e.printStackTrace();
226
+
227
+ }
228
+
229
+ }
230
+
231
+ streamID = info.effectID;
232
+
233
+ mPlayWhenLoadedEffects.remove(soundID);
234
+
235
+ }
236
+
237
+
238
+
239
+ return streamID;
240
+
241
+ }
242
+
243
+
244
+
245
+ //(略)
246
+
247
+
248
+
249
+ public int createSoundIDFromAsset(final String path) {
250
+
251
+ int soundID = Cocos2dxSound.INVALID_SOUND_ID;
252
+
253
+
254
+
255
+ try {
256
+
257
+ if (path.startsWith("/")) {
258
+
259
+ soundID = this.mSoundPool.load(path, 0);
260
+
261
+ } else {
262
+
263
+ soundID = this.mSoundPool.load(this.mContext.getAssets().openFd(path), 0);
264
+
265
+ }
266
+
267
+ } catch (final Exception e) {
268
+
269
+ soundID = Cocos2dxSound.INVALID_SOUND_ID;
270
+
271
+ Log.e(Cocos2dxSound.TAG, "error: " + e.getMessage(), e);
272
+
273
+ }
274
+
275
+
276
+
277
+ // mSoundPool.load returns 0 if something goes wrong, for example a file does not exist
278
+
279
+ if (soundID == 0) {
280
+
281
+ soundID = Cocos2dxSound.INVALID_SOUND_ID;
282
+
283
+ }
284
+
285
+
286
+
287
+ return soundID;
288
+
289
+ }
290
+
291
+ ```
292
+
293
+
294
+
295
+ Cocos2dxHelper.java:268付近
296
+
297
+ ```
298
+
299
+ public static int playEffect(final String path, final boolean isLoop, final float pitch, final float pan, final float gain) {
300
+
301
+ return Cocos2dxHelper.sCocos2dSound.playEffect(path, isLoop, pitch, pan, gain);
302
+
303
+ }
304
+
305
+ ```
306
+
307
+
308
+
309
+ Cocos2dxRenderer.java:104付近
310
+
311
+ ```
312
+
313
+ public void onDrawFrame(final GL10 gl) {
314
+
315
+ /*
316
+
317
+ * No need to use algorithm in default(60 FPS) situation,
318
+
319
+ * since onDrawFrame() was called by system 60 times per second by default.
320
+
321
+ */
322
+
323
+ if (sAnimationInterval <= 1.0 / 60 * Cocos2dxRenderer.NANOSECONDSPERSECOND) {
324
+
325
+ Cocos2dxRenderer.nativeRender();
326
+
327
+ } else {
328
+
329
+ final long now = System.nanoTime();
330
+
331
+ final long interval = now - this.mLastTickInNanoSeconds;
332
+
333
+
334
+
335
+ if (interval < Cocos2dxRenderer.sAnimationInterval) {
336
+
337
+ try {
338
+
339
+ Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
340
+
341
+ } catch (final Exception e) {
342
+
343
+ }
344
+
345
+ }
346
+
347
+ /*
348
+
349
+ * Render time MUST be counted in, or the FPS will slower than appointed.
350
+
351
+ */
352
+
353
+ this.mLastTickInNanoSeconds = System.nanoTime();
354
+
355
+ Cocos2dxRenderer.nativeRender();
356
+
357
+ }
358
+
359
+ }
360
+
361
+ ```
362
+
363
+
364
+
365
+
366
+
367
+ ###補足情報
44
368
 
45
369
  cocos2d-x-3.9
46
370
 
47
-
371
+ AndroidStudio2.2.3
48
-
372
+
373
+
374
+
49
- (追記)再生しようとしているファイルはmp3です。
375
+ (追記)再生しようとしているファイルはmp3です。Resources/bgm/main.mp3
50
-
51
-
52
-
376
+
53
- 回答お待ちしてます。
377
+ (追記)元のMainScene.cpp(BGM鳴らしたいだけのコードですが)とエラーの発生しているCocosなんゃら.javaの該当部分を追記させていただきまた。AssetManager.java、GLSurfaceView.javaはconsole欄で灰色表示になったので弄らないでということでしょうか、、、不足がありしたらまた書き込ませていただきまのでよろしくお願いします。。

1

再生ファイルのフォーマット追記

2017/04/18 09:53

投稿

5_m_8_r_9
5_m_8_r_9

スコア7

test CHANGED
@@ -1 +1 @@
1
- AndroidStudioでCocos2dxSoundのエラーメッセージ
1
+ AndroidStudioでCocos2dxSound.javaのエラーメッセージ
test CHANGED
@@ -46,4 +46,8 @@
46
46
 
47
47
 
48
48
 
49
+ (追記)再生しようとしているファイルはmp3です。
50
+
51
+
52
+
49
53
  回答お待ちしてます。