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

質問編集履歴

2

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

2017/04/18 09:53

投稿

5_m_8_r_9
5_m_8_r_9

スコア7

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  ###発生している問題・エラーメッセージ
5
5
 
6
+ console欄エラーメッセージ
6
7
  ```
7
8
  E/Cocos2dxSound: error:
8
9
  java.io.FileNotFoundException:
@@ -19,9 +20,170 @@
19
20
  ```
20
21
 
21
22
 
23
+ MainScene.cpp
24
+ ```C++
25
+ #include "MainScene.h"
26
+ #include "SimpleAudioEngine.h"
27
+
28
+ USING_NS_CC;
29
+
30
+ MainScene::MainScene() {
31
+ }
32
+
33
+ MainScene::~MainScene() {
34
+ }
35
+
36
+ Scene* MainScene::createScene() {
37
+ auto scene = Scene::create();
38
+ auto layer = MainScene::create();
39
+ scene->addChild(layer);
40
+ return scene;
41
+ }
42
+
43
+ bool MainScene::init() {
44
+ if ( !Layer::init() ) {
45
+ return false;
46
+ }
47
+ CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("main.mp3");
48
+
49
+ return true;
50
+ }
51
+
52
+ void MainScene::onEnter() {
53
+ Layer::onEnter();
54
+ }
55
+
56
+ void MainScene::onEnterTransitionDidFinish() {
57
+ Layer::onEnterTransitionDidFinish();
58
+
59
+ CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("main.mp3", true);
60
+ }
61
+ ```
62
+
63
+
64
+ Cocos2dxSound.java エラー付近(108,149,282)
65
+ ```
66
+ //(略)
67
+
68
+ public int preloadEffect(final String path) {
69
+ if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
70
+ CocosPlayClient.updateAssets(path);
71
+ }
72
+ CocosPlayClient.notifyFileLoaded(path);
73
+ Integer soundID = this.mPathSoundIDMap.get(path);
74
+
75
+ if (soundID == null) {
76
+ soundID = this.createSoundIDFromAsset(path);
77
+ // save value just in case if file is really loaded
78
+ if (soundID != Cocos2dxSound.INVALID_SOUND_ID) {
79
+ this.mPathSoundIDMap.put(path, soundID);
80
+ }
81
+ }
82
+
83
+ return soundID;
84
+ }
85
+
86
+ //(略)
87
+
88
+ public int playEffect(final String path, final boolean loop, float pitch, float pan, float gain){
89
+ Integer soundID = this.mPathSoundIDMap.get(path);
90
+ int streamID = Cocos2dxSound.INVALID_STREAM_ID;
91
+
92
+ if (soundID != null) {
93
+ // parameters; pan = -1 for left channel, 1 for right channel, 0 for both channels
94
+
22
- ###補足情報(言語/FW/ツール等のバージョンなど)
95
+ // play sound
96
+ streamID = this.doPlayEffect(path, soundID, loop, pitch, pan, gain);
97
+ } else {
98
+ // the effect is not prepared
99
+ soundID = this.preloadEffect(path);
100
+ if (soundID == Cocos2dxSound.INVALID_SOUND_ID) {
101
+ // can not preload effect
102
+ return Cocos2dxSound.INVALID_SOUND_ID;
103
+ }
104
+
105
+ SoundInfoForLoadedCompleted info = new SoundInfoForLoadedCompleted(path, loop, pitch, pan, gain);
106
+ mPlayWhenLoadedEffects.putIfAbsent(soundID, info);
107
+
108
+ synchronized(info) {
109
+ try {
110
+ info.wait(LOAD_TIME_OUT);
111
+ }
112
+ catch (Exception e) {
113
+ e.printStackTrace();
114
+ }
115
+ }
116
+ streamID = info.effectID;
117
+ mPlayWhenLoadedEffects.remove(soundID);
118
+ }
119
+
120
+ return streamID;
121
+ }
122
+
123
+ //(略)
124
+
125
+ public int createSoundIDFromAsset(final String path) {
126
+ int soundID = Cocos2dxSound.INVALID_SOUND_ID;
127
+
128
+ try {
129
+ if (path.startsWith("/")) {
130
+ soundID = this.mSoundPool.load(path, 0);
131
+ } else {
132
+ soundID = this.mSoundPool.load(this.mContext.getAssets().openFd(path), 0);
133
+ }
134
+ } catch (final Exception e) {
135
+ soundID = Cocos2dxSound.INVALID_SOUND_ID;
136
+ Log.e(Cocos2dxSound.TAG, "error: " + e.getMessage(), e);
137
+ }
138
+
139
+ // mSoundPool.load returns 0 if something goes wrong, for example a file does not exist
140
+ if (soundID == 0) {
141
+ soundID = Cocos2dxSound.INVALID_SOUND_ID;
142
+ }
143
+
144
+ return soundID;
145
+ }
146
+ ```
147
+
148
+ Cocos2dxHelper.java:268付近
149
+ ```
150
+ public static int playEffect(final String path, final boolean isLoop, final float pitch, final float pan, final float gain) {
151
+ return Cocos2dxHelper.sCocos2dSound.playEffect(path, isLoop, pitch, pan, gain);
152
+ }
153
+ ```
154
+
155
+ Cocos2dxRenderer.java:104付近
156
+ ```
157
+ public void onDrawFrame(final GL10 gl) {
158
+ /*
159
+ * No need to use algorithm in default(60 FPS) situation,
160
+ * since onDrawFrame() was called by system 60 times per second by default.
161
+ */
162
+ if (sAnimationInterval <= 1.0 / 60 * Cocos2dxRenderer.NANOSECONDSPERSECOND) {
163
+ Cocos2dxRenderer.nativeRender();
164
+ } else {
165
+ final long now = System.nanoTime();
166
+ final long interval = now - this.mLastTickInNanoSeconds;
167
+
168
+ if (interval < Cocos2dxRenderer.sAnimationInterval) {
169
+ try {
170
+ Thread.sleep((Cocos2dxRenderer.sAnimationInterval - interval) / Cocos2dxRenderer.NANOSECONDSPERMICROSECOND);
171
+ } catch (final Exception e) {
172
+ }
173
+ }
174
+ /*
175
+ * Render time MUST be counted in, or the FPS will slower than appointed.
176
+ */
177
+ this.mLastTickInNanoSeconds = System.nanoTime();
178
+ Cocos2dxRenderer.nativeRender();
179
+ }
180
+ }
181
+ ```
182
+
183
+
184
+ ###補足情報
23
185
  cocos2d-x-3.9
186
+ AndroidStudio2.2.3
24
187
 
25
- (追記)再生しようとしているファイルはmp3です。
188
+ (追記)再生しようとしているファイルはmp3です。Resources/bgm/main.mp3
26
-
27
- 回答お待ちしてます。
189
+ (追記)元の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

title CHANGED
@@ -1,1 +1,1 @@
1
- AndroidStudioでCocos2dxSoundのエラーメッセージ
1
+ AndroidStudioでCocos2dxSound.javaのエラーメッセージ
body CHANGED
@@ -22,4 +22,6 @@
22
22
  ###補足情報(言語/FW/ツール等のバージョンなど)
23
23
  cocos2d-x-3.9
24
24
 
25
+ (追記)再生しようとしているファイルはmp3です。
26
+
25
27
  回答お待ちしてます。