Sound Not Working.
Monkey Targets Forums/HTML5/Sound Not Working.
| ||
| I'm sure that I'm doing everything correctly; I'm convinced the sound effects are loading and have been properly implemented in my game and yet they refuse to play regardless of which sound file format I use, i.e WAV, MP3, OGG or AAC running my HTML5 game under Internet Explorer 10. I intentionally have included only one sound effect as a self test which I have placed in the Attract_Mode method. Below are the MServer report, ( if it's of any use ), and game code. MServer 0.3 MServer active and listening on port 50607 1> HTTP Server active and listening on port 49450 1:1> GET C:/MonkeyPro77b/TableTennis.build/html5/MonkeyGame.html (200 OK) 1:1> GET C:/MonkeyPro77b/TableTennis.build/html5/main.js (200 OK) 1:1> GET C:/MonkeyPro77b/TableTennis.build/html5/data/mojo_font.png (200 OK) 1:1> GET C:/MonkeyPro77b/TableTennis.build/html5/data/Chilli_Bean.wav (200 OK) 1:1> BYE 1:3> GET C:/MonkeyPro77b/TableTennis.build/html5/favicon.ico (200 OK) 1:2> BYE 1:4> BYE 1:3> BYE
Strict
Import mojo
Function Main:Int()
New TableTennis
Return True
End
Class TableTennis Extends App 'Beginning of TableTennis Class declaration
Const CRT_WIDTH:Float = 630.0
Const CRT_HEIGHT:Float = 470.0
Const CRT_LFT:Float = CRT_HEIGHT + CRT_LINE_WIDTH
Const CRT_RT:Float = CRT_LINE_WIDTH
Const CRT_OPNT_END:Float = CRT_LINE_WIDTH
Const CRT_PLR_END:Float = CRT_WIDTH
Const CRT_LINE_WIDTH:Float = 5.0
Const PLR_WIDTH:Float = 5.0
Const PLR_HEIGHT:Float = 40.0
Const PLR_OUTR_LFT:Float = PLR_HEIGHT - BALL_RDS
Const PLR_CNTR_LFT:Float = PLR_HEIGHT/2 + BALL_RDS
Const PLR_CNTR_RT:Float = PLR_HEIGHT/2 - BALL_RDS
Const PLR_X_POS_START:Float = CRT_WIDTH - ( PLR_WIDTH * 2 )
Const PLR_Y_POS_START:Float = ( CRT_HEIGHT/2 - PLR_HEIGHT/2 ) + CRT_LINE_WIDTH
Const PLR_SPD_START:Float = 5.0
Const PLR_PNTS_START:Int = 0
Const OPNT_WIDTH:Float = 5.0
Const OPNT_HEIGHT:Float = 40.0
Const OPNT_CNTR_LFT:Float = OPNT_HEIGHT/2 - BALL_RDS
Const OPNT_CNTR_RT:Float = OPNT_HEIGHT/2 + BALL_RDS
Const OPNT_OUTR_RT:Float = OPNT_HEIGHT - BALL_RDS
Const OPNT_0_X_POS_START:Float = CRT_LINE_WIDTH + ( OPNT_WIDTH * 2 )
Const OPNT_1_X_POS_START:Float = CRT_LINE_WIDTH + ( OPNT_WIDTH * 7 )
Const OPNT_0_Y_POS_START:Float = ( CRT_HEIGHT/2 - OPNT_HEIGHT/2 ) + CRT_LINE_WIDTH
Const OPNT_1_Y_POS_START:Float = ( CRT_HEIGHT/2 - OPNT_HEIGHT/2 ) + CRT_LINE_WIDTH
Const OPNT_0_SPD_START:Float = -5.0
Const OPNT_1_SPD_START:Float = 3.0
Const OPNT_PNTS_START:Int = 0
Const BALL_RDS:Float = 5.0
Const BALL_X_POS_START:Float = CRT_WIDTH/2 + BALL_RDS
Const BALL_Y_POS_START:Float = CRT_HEIGHT/2 + BALL_RDS
Const BALL_X_SPD_START:Float = 3.0
Const BALL_Y_SPD_START:Float = 1.0
Const GAME_OVER_PNTS:Int = 10
Field plr_X_pos:Float = PLR_X_POS_START
Field plr_Y_pos:Float = PLR_Y_POS_START
Global plr_prev_Y_pos:Float
Field plr_Y_spd:Float = PLR_SPD_START
Field plr_pnts:Int = PLR_PNTS_START
Field opnt_X_pos:Float[] = [ OPNT_0_X_POS_START , OPNT_1_X_POS_START ]
Field opnt_Y_pos:Float[] = [ OPNT_0_Y_POS_START , OPNT_1_Y_POS_START ]
Field opnt_Y_spd:Float[] = [ OPNT_0_SPD_START , OPNT_1_SPD_START ]
Field opnt_pnts:Int = OPNT_PNTS_START
Field ball_X_pos:Float = BALL_X_POS_START
Field ball_Y_pos:Float = BALL_Y_POS_START
Field ball_X_spd:Float = BALL_X_SPD_START
Field ball_Y_spd:Float = BALL_Y_SPD_START
Field game_mode:Int = 0 'Gamemode: 0 = Attract Mode , 1 = Game In Play , 2 = Game Over
Field SFX_game_start:Sound
Field SFX_game_over:Sound
Field SFX_plr_hit_ball:Sound
Field SFX_plr_miss_ball:Sound
Field SFX_opnt_hit_ball:Sound
Field SFX_opnt_miss_ball:Sound
Field SFX_bounce_court_left:Sound
Field SFX_bounce_court_right:Sound
Field SFX_plr_win:Sound
Field SFX_opnt_win:Sound
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method OnCreate:Int()
SetUpdateRate(60)
SFX_game_start = LoadSound ( "Chilli_Bean.wav" )
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method OnUpdate:Int()
Select game_mode
Case 0
Attract_Mode()
Case 1
Update_Game()
Case 2
Game_Over()
End Select
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method OnRender:Int()
Cls
DRAW_TennisCourt()
DRAW_Player()
DRAW_Opponent()
DRAW_Score()
DRAW_Ball()
Select game_mode
Case 0
DRAW_Attract_Mode()
Case 2
DRAW_Game_Over()
End Select
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method CONTROL_Player:Int()
plr_prev_Y_pos = plr_Y_pos
'If MouseY() > 0 Then plr_Y_pos = MouseY()
If KeyDown ( KEY_UP ) Then
plr_Y_pos -= plr_Y_spd
If plr_Y_pos < CRT_RT Then
plr_Y_pos = CRT_RT
Endif
Endif
If KeyDown ( KEY_DOWN ) Then
plr_Y_pos += plr_Y_spd
If plr_Y_pos > ( CRT_LFT - PLR_HEIGHT ) Then
plr_Y_pos = ( CRT_LFT - PLR_HEIGHT )
Endif
Endif
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method MOVEMENT_Ball:Int()
ball_X_pos += ball_X_spd
ball_Y_pos += ball_Y_spd
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method MOVEMENT_Opponent:Int()
For Local opnt:Int = 0 To 1
opnt_Y_pos[opnt] += opnt_Y_spd[opnt]
If opnt_Y_pos [opnt] < CRT_RT Then
opnt_Y_pos [opnt] = CRT_RT
opnt_Y_spd [opnt] *= -1
Endif
If opnt_Y_pos [opnt] > ( CRT_LFT - OPNT_HEIGHT ) Then
opnt_Y_pos [opnt] = ( CRT_LFT - OPNT_HEIGHT )
opnt_Y_spd [opnt] *= -1
Endif
Next
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method COLLISION_Ball_With_Court:Int()
If ball_Y_pos <= ( CRT_RT + BALL_RDS ) Then 'Check Ball Has Hit "Court Right" ( Top Of Play Area )
ball_Y_pos = ( CRT_RT + BALL_RDS )
ball_Y_spd *= -1
Endif
If ball_Y_pos >= ( CRT_LFT - BALL_RDS ) Then 'Check Ball Has Hit "Court Left" ( Bottom Of Play Area )
ball_Y_pos = ( CRT_LFT - BALL_RDS )
ball_Y_spd *= -1
Endif
If ball_X_pos <= ( CRT_OPNT_END + BALL_RDS ) Then 'Check Ball Has Hit "Opponent's End Of Court" ( Left Of Play Area )
ball_X_pos = ( CRT_OPNT_END + BALL_RDS )
ball_X_spd *= -1
plr_pnts += 1 'Award Player Points If Opponent Misses Ball
If plr_pnts >= GAME_OVER_PNTS Then game_mode = 2
Endif
If ball_X_pos >= CRT_PLR_END Then 'Check Ball Has Hit "Player's End Of Court" ( Right Of Play Area )
ball_X_pos = CRT_PLR_END
ball_X_spd *= -1
opnt_pnts += 1 'Award Opponent Points If Player Misses Ball
If opnt_pnts >= GAME_OVER_PNTS Then game_mode = 2
Endif
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method COLLISION_Ball_With_Player:Int()
If ball_X_pos > ( plr_X_pos - BALL_RDS ) And ball_X_spd > 0 Then
If ( ball_Y_pos >= plr_Y_pos ) And ( ball_Y_pos <= ( plr_Y_pos + PLR_HEIGHT )) Then
ball_X_pos = ( plr_X_pos - BALL_RDS )
ball_X_spd *= -1
If ( ball_Y_pos > plr_Y_pos ) And ( ball_Y_pos < ( plr_Y_pos + PLR_CNTR_RT )) Then
ball_Y_spd += ( plr_Y_pos - plr_prev_Y_pos ) * 0.25
If ball_Y_spd > 0 Then ball_Y_spd *= -1
Endif
If ( ball_Y_pos > ( plr_Y_pos + PLR_CNTR_RT )) And ( ball_Y_pos < ( plr_Y_pos + PLR_CNTR_LFT )) Then ball_Y_spd = 0.0
If ( ball_Y_pos > ( plr_Y_pos + PLR_CNTR_LFT )) And ( ball_Y_pos < ( plr_Y_pos + PLR_HEIGHT )) Then
ball_Y_spd += ( plr_Y_pos - plr_prev_Y_pos ) * 0.25
If ball_Y_spd < 0 Then ball_Y_spd *= -1
Endif
Endif
Endif
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method COLLISION_Ball_With_Opponent_0_Or_1:Int()
For Local opnt:Int = 0 To 1
If ( ball_X_pos > ( opnt_X_pos[opnt] - BALL_RDS )) And ( ball_X_pos < ( opnt_X_pos[opnt] + BALL_RDS*2 )) Then
If ( ball_Y_pos >= opnt_Y_pos[opnt] ) And ( ball_Y_pos <= ( opnt_Y_pos[opnt] + OPNT_HEIGHT )) Then
Return opnt
Endif
Endif
Next
Return -1
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method COLLISION_Ball_With_Opponent:Int()
Local opnt:Int = COLLISION_Ball_With_Opponent_0_Or_1()
If opnt >= 0 And ball_X_spd < 0 Then
ball_X_pos = ( opnt_X_pos[opnt] + ( BALL_RDS*2 ))
ball_X_spd *= -1
If ( ball_Y_pos > opnt_Y_pos[opnt] ) And ( ball_Y_pos < ( opnt_Y_pos[opnt] + OPNT_CNTR_LFT )) Then ball_Y_spd = -1.0
If ( ball_Y_pos > ( opnt_Y_pos[opnt] + OPNT_CNTR_LFT )) And ( ball_Y_pos < ( opnt_Y_pos[opnt] + OPNT_CNTR_RT )) Then ball_Y_spd = 0.0
If ( ball_Y_pos > ( opnt_Y_pos[opnt] + OPNT_CNTR_RT )) And ( ball_Y_pos < ( opnt_Y_pos[opnt] + OPNT_HEIGHT )) Then ball_Y_spd = 1.0
Endif
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method Update_Game:Int()
CONTROL_Player()
MOVEMENT_Ball()
MOVEMENT_Opponent()
COLLISION_Ball_With_Court()
COLLISION_Ball_With_Player()
COLLISION_Ball_With_Opponent()
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method Attract_Mode:Int()
If KeyHit ( KEY_SPACE ) Then
PlaySound ( SFX_game_start )
game_mode = 1 'Begin Game
Endif
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method Game_Over:Int()
If KeyHit ( KEY_SPACE ) Then
plr_pnts = PLR_PNTS_START
plr_X_pos = PLR_X_POS_START
plr_Y_pos = PLR_Y_POS_START
plr_Y_spd = PLR_SPD_START
opnt_pnts = OPNT_PNTS_START
opnt_X_pos[0] = OPNT_0_X_POS_START
opnt_X_pos[1] = OPNT_1_X_POS_START
opnt_Y_pos[0] = OPNT_0_Y_POS_START
opnt_Y_pos[1] = OPNT_1_Y_POS_START
opnt_Y_spd[0] = OPNT_0_SPD_START
opnt_Y_spd[1] = OPNT_1_SPD_START
ball_X_pos = BALL_X_POS_START
ball_Y_pos = BALL_Y_POS_START
ball_X_spd = BALL_X_SPD_START
ball_Y_spd = BALL_Y_SPD_START
game_mode = 1
Endif
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_TennisCourt:Int()
SetColor ( 255 , 255 , 255 )
DrawRect ( 0,0 , 640,480 )
SetColor ( 0 , 160 , 80 )
DrawRect ( 5,5 , 630,470 )
SetColor ( 255 , 255 , 255 )
For Local i:Int = 10 To 460 Step 15
DrawRect ( 318,i , 5,10)
Next
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Player:Int()
SetColor ( 0 , 0 , 255 )
DrawRect ( plr_X_pos , plr_Y_pos , PLR_WIDTH , PLR_HEIGHT ) 'Draw The Player's Bat
Return True
End
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Opponent:Int()
SetColor ( 255 , 0 , 0 )
DrawRect ( opnt_X_pos[0] , opnt_Y_pos[0] , OPNT_WIDTH , OPNT_HEIGHT ) 'Draw 1st Opponent
DrawRect ( opnt_X_pos[1] , opnt_Y_pos[1] , OPNT_WIDTH , OPNT_HEIGHT ) 'Draw 2nd Opponent
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Ball:Int()
SetColor ( 255 , 255 , 0 ) 'Change Colour To Yellow For Tennis Ball
DrawCircle ( ball_X_pos , ball_Y_pos , BALL_RDS ) 'Draw Tennis Ball
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Score:Int()
SetColor ( 255 , 255 , 255 )
DrawText ( "Opponent's Points: " + opnt_pnts , 85 , 10 )
DrawText ( "Player's Points: " + plr_pnts , 415 , 10 )
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Attract_Mode:Int()
SetColor ( 255 , 255 , 0 )
DrawText ( "Welcome to 'Table Tennis'." , 230 , 60 )
DrawText ( "Press 'Spacebar' to Play. Press 'P' to Pause." , 160 , 74 )
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Method DRAW_Game_Over:Int()
SetColor ( 255 , 255 , 0 )
DrawText ( "G A M E O V E R" , 265 , 60 )
If opnt_pnts >= GAME_OVER_PNTS Then
SetColor ( 255 , 0 , 0 )
DrawText ( "The Computer Won This Time :(" , 215 , 74 )
DrawText ( "Defeating You By " + ( opnt_pnts - plr_pnts ) + " Points" , 230 , 88 )
Else
SetColor ( 0 , 0 , 255 )
DrawText ( "Congratulations, You Won! :)" , 220 , 74 )
DrawText ( "You Defeated The Computer By " + ( plr_pnts - opnt_pnts ) + " Points" , 190 , 88 )
Endif
SetColor ( 255 , 255 , 0 )
DrawText ( "Press 'Spacebar' To Play Again." , 210 , 102 )
Return True
End
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End 'End of TableTennis Class
|
| ||
| Hi Stuart, first of all there are a few things to check. Start by making sure that your build/html5/data folder contains the correct sound files, you may have tweaked the config file which controls what file types get moved, if the sound files are there and its still not playing then It's probably a support issue from the browser, here is a handy page you can check for compatability between audio formats and the main browsers, just scroll down a little . http://www.w3schools.com/html/html5_audio.asp But from the looks of it, IE does not support WAV files, so your code is probably find but your browser does not like the audio file format that your trying to use, I also may be wrong but I think Flash hates underscores so try removing that as well. |
| ||
| I've checked everything and all seems to be as it should be, I've changed the .WAV file to .MP3 except it still does not work with Internet Explorer. When I swap over to Chrome the sound file does play though the MServer report displays the following: 1:1> GET C:/MonkeyPro77b/TableTennis.build/html5/data/Chilli_Bean.mp3 (206 Partial Content: 0-63989) Is the above anything to be concerned about, what does it mean? |
| ||
| Next step would be to try a monkey banana sample: Does "C:/MonkeyPro77b/bananas/mak/audiotest/audiotest.monkey" produce any sound? How big (long) is your sound? Did you convert the sound with Audacity? |
| ||
| audiotest.monkey doesn't work either :( it's perplexing to say the least lol |
| ||
| Does this plays any music/sound for you in Firefox/Chrome? It won't play on IE because I didn't convert everything to MP3s... |
| ||
| The fact that your audio is working on Chrome tells you that it's deffinatly the browser's fault, support for Audio is still very bad for html5 and they have all failed to come to a standard which we hope they do soon, personally I think the reason they have not is that their trying to make developers build for their browser specifically(tinfoil hat off) .. One thing you might try if the mp3 fails on IE, is to change the bit rate of the Mp3, load it up in something like Audiacity and change its rate to 44k then save it out again. |
| ||
| Hmmm... something did break in Monkey 77a! Sound stopped working for me on IE too! (It works fine on Chrome and Firefox, but on IE even the audiotest is mute, sometimes giving "audio error1" Edit: Monkey76d with the same problem... Edit2: tested up to monkey 73, and no sound on IE running audiotest. Doesn't seems to be a IE problem, trying the test code from this page, it works: http://blogs.msdn.com/b/ie/archive/2011/05/13/unlocking-the-power-of-html5-lt-audio-gt.aspx Edit3: used the code of the page above, with the same mp3 I try to play on my game and it works. But on Monkey, mp3 is loaded, and no sound gets played. Definitively a bug in Monkey/IE! Edit4: ACK! I give up - after some time, now my game is playing sound/music on IE (with tons of lag, but it is playing...) while locally I don't hear anything. Go figure. |
| ||
| As Chrome supports MP3, WAV, OGG and AAC, ( though more importantly my sound effects work - woohoo! lol ), I shall stick with Chrome; I may be wrong but it does seem to be the better Web Browser. I thank you all sincerely for your time, help and offers of solutions; I may perhaps attempt one last time to get sound effects working under I.E but if this isn't successful then I'm not bothered. Incidentally, SLotman, I like your game very much and aspire to write a game like this myself in the near future. Cheers, guys! |
| ||
| Thanks Stuart! Be sure to upload your game somewhere and try it... I now am assuming something between mserver and IE is the problem somehow. |
| ||
| Have you tried the howler.js library. I tried it and it does seem to work on every browser i tried, including the standard android browser http://www.monkeycoder.co.nz/Community/posts.php?topic=5816&post=70242 |
| ||
| It may be related to mserver. I did add some meta/type information to it in the past, but not sure I added the audio extensions and it may be confusing some browsers. If anyone fancy taking a look to see if the same app works when executed from a proper remote server (or apache, etc.) |
| ||
| remote server , fails sound in ie 9 , and 11 . one of my work computers is locked to ie 9 . lol the html5 audio test page works on the ie 9 and 11 . . tested with monkey 78c |
| ||
| Prime_8 wrote: remote server , fails sound in ie 9 , and 11 . one of my work computers is locked to ie 9 . lol MSIE 11 user-agent has no "MSIE" word, use "Trident" to define any IE version. Example: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko #Elseif TARGET="html5" ' 'HTML5 supports WAV, OGG, MP3, M4A. However... ' 'IE wont play WAV/OGG 'FF wont play MP3/M4A/WAV ' soundFmt="wav" musicFmt="ogg" If UserAgent.Contains( "Trident" ) soundFmt="mp3" musicFmt="mp3" Print "IE" Endif 'Print UserAgent It doesn't help if you are still opening game from localhost. MSIE doesn't play media files from local computer, but plays from internet or local file system (with alert at start). I tested this url in IE11, it works fine. http://www.softexe.com/mp3/monkeygame.html |
| ||
| It is a bug in mserver 0.3 It returns 1 extra char (;) in the Content-Type: "audio/mpeg;" instead "audio/mpeg" WriteLine(stream, "Content-Type: " + content + ";") I will form bug report. |