Requirements:
The background music must be played continuously, regardless of whether the scenario is switched or not, and played cyclically at the same time. In addition, each scenario has its own voice (commentary ).
Solution:
<krpano onstart="playsound(bg, backgroundmusic.mp3,0); loadscene(scene1,null,MERGE);"> <plugin name="soundinterface" url="soundinterface.swf" alturl="soundinterface.js" preload="true" /> <scene name="scene1"> <events name="scene1events" onxmlcomplete="tween(sound[bg].volume, 0.5);playsound(scene1sound, scene1music.mp3,1,tween(sound[bg].volume, 1));" onremovepano="stopsound(scene1sound);" /> ... </scene> <scene name="scene2"> <events name="scene2events" onxmlcomplete="tween(sound[bg].volume, 0.5);playsound(scene2sound, scene2music.mp3,1,tween(sound[bg].volume, 1));" onremovepano="stopsound(scene2sound);" /> ... </scene></krpano>
Details:
onstart="playsound(bg, backgroundmusic.mp3,0);
Bgstands for the name of the audio, and 0 stands for loop playback.
<plugin name="soundinterface" url="%SWFPATH%/plugins/soundinterface.swf" alturl="%SWFPATH%/plugins/soundinterface.js" preload="true" />
This code is required for playing a sound during roaming. Preload = "true" ensures that the soundinterface plug-in can be pre-loaded. The swf and js files Ensure smooth cross-platform playback. Place the correct path here.
<events name="scene1events" onxmlcomplete="tween(sound[bg].volume, 0.5);playsound(scene1sound, scene1music.mp3,1,tween(sound[bg].volume, 1));" onremovepano="stopsound(scene1sound);" />
. When the onremovepano event occurs in this scenario, stop playing the sound whose name is scene1sound. Therefore, this is a local event, so this event is only valid within the effective time of the scene. For other scene, use the same method. Note that the path and name are correct.
Tween (sound [bg]. volume, 0.5) makes the volume of background music gradient from 1 to 0.5 at the beginning of the commentary, tween (sound [bg]. volume, 1) is an oncomplete action, that is, when the commentary is played, the volume of the background music is restored to 1.
Tip:
IOS (iPhone/iPad) Considerations
Ios devices have additional System Restrictions on sound playback:
· Automatic playback failure/automatic start
Cannot play a sound automatically! The viewer's interaction behavior is required to activate the playing sound, such as touching the screen. Krpano automatically detects the interaction and does not need to specify a button.
· Only one sound can be played at a time
This means that it is impossible to play two or more sounds simultaneously on the ios device. When a new playsound function appears, the previous sound will automatically stop. Therefore, you can only use the background sound or commentary.
· The volume cannot be changed.
You cannot control the volume by using krpano.
Technical support and requirements:
Please contact QQ 178941086 to indicate"CSDN blog"