PlayMusic and looping music
Monkey Targets Forums/HTML5/PlayMusic and looping music
| ||
I noticed that in HTML 5 + Firefox, PlayMusic("music.ogg",1) does not loop the music. (It does loop in HTML 5 + Chrome.) Therefore, for the time being, I have added this MusicState check to OnUpdate to achieve a "manual" kind of looping: Method OnUpdate:Int() ' music is not playing If (MusicState() = 0) Then ' start music PlayMusic("music.ogg",1) End If End Method There is a slight pause between two plays. By the way, I switched to using OGG for music in HTML 5 (MP3 in Flash) since my song, which lasts only about 5 seconds, would be sized 600 KB in WAV, while the OGG version is only 70 KB. Of course the downside of OGG is that it does not work under IE. So people who play my game as HTML 5 + IE would hear no music at all. In that respect I suppose HTML 5 is still to be seen as "hey that's nice that it works as HTML 5 too" but not as the main target to make a game for. |
| ||
Of course the downside of OGG is that it does not work under IE. So people who play my game as HTML 5 + IE would hear no music at all. Can't you check the browser ID string and if it's IE then load/use the WAV file else use/load the OGG? EDIT: See here. |
| ||
That is very useful, thanks. I could then use the MP3 version for IE. |
| ||
With the user-agent check added I am now using this TSoundSystem class for playing music from my HTML5 / Flash game:' soundsystem.monkey Import mojo Extern Function getUserAgent:String() = "function (){return navigator.userAgent;}" Public Class TSoundSystem Global gMusicExtension:String Global gMusicEnabled:Bool = True Function init:Void() ' default value gMusicExtension = "mp3" ' target is flash #if TARGET="flash" gMusicExtension = "mp3" #end ' target is html5 #if TARGET="html5" Local userAgent:String = getUserAgent() ' browser is probably IE If (userAgent.Find("MSIE") <> -1) Then gMusicExtension = "mp3" ' browser is probably non-IE Else gMusicExtension = "ogg" End If #end End Function Function playMusic:Void(pBaseFileName:String) If (gMusicEnabled) Then PlayMusic("music/"+pBaseFileName+"."+gMusicExtension,1) End If End Function End I know the way I check for MSIE in the user-agent string is not perfect, as for example Opera might also have MSIE in the user-agent. (As explained in the link posted by therevills here). My main concern is however to have music playing in FF, IE, and Chrome. Now I can use TSoundSystem.init() at the start of my game, it will decide what extension is to be used. Afterwards I can use TSoundSystem.playMusic("mymusic") and it will play the correct one, assuming that both mymusic.ogg and mymusic.mp3 are available in my /music folder. |
| ||
I have had trouble with sound too. I have considered directing IE users to Chrome Frame. Haven't tried it myself, but according to the documentation, you don't need administrative rights to install it. Though I suppose you don't need administrative rights to install the Chrome Browser either. I guess with the frame, you're still "running" IE but you're actually using Google's V8 Engine. Perhaps there is a way trigger the installation automatically? http://code.google.com/chrome/chromeframe/ |