+1
Beantwortet

stop sound action when user scroll / swipe away from a page

paololuk vor 12 Jahren aktualisiert von icahill (Administrator) vor 12 Jahren 6
I have this code. I want to stop the sound when the user scrolls away from the first page. Maybe the action soundstop doesn't target the right sound. I dont know...
Thanks

<!-- main wire hierarchy -->

<!-- intro -->
<action name="initialize" oninit="yes" >
<play action="sound1" />
</action>
<action name="sound1">
<sound action="play" source="other/arpa" type="mp3" />
</action>
<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>
<action name="stopsound">
<play action="soundstop"/>
</action>

<!-- carica pdf -->
<pdf name="vitadigesu" source="graphics/vitadigesu_ver4_retina_vettori.pdf" height="100%" width="100%" spreads="no" covertile="yes" tile="yes">

<!-- pannelli link - credits - aiuto - testi -->
<panel name="sound_arpa" alias="SOUND_ARPA" clip="yes" width="100%" height="100%" alpha="1" onpage="1" onscrollaway="stopsound"> </panel>
This is a known bug for page one of a pager or pdf and onscrollaway actions. As a work around you can assign a variable to help with your action:

<wire>
<main>
<panel name="main" width="100%" height="100%">
<!--This would be a pdf in your case. The onscrollto needs to be put on several pages to account for "speed scrolling". you can put a 1px transparent panel in the corner that can take the onscrollto-->
<pager name="pager" width="100%" height="200" orientation="horizontal" paginate="yes">
<panel name="1" width="25%" height="100%" background="ff0000" onscrollto="page1" onscrollaway="alert" _alert="1"></panel>
<panel name="2" width="25%" height="100%" background="ffff00" onscrollto="page1" onscrollaway="alert" _alert="2"></panel>
<panel name="3" width="25%" height="100%" background="ffffff" onscrollto="page1" onscrollaway="alert" _alert="3"></panel>
<panel name="4" width="25%" height="100%" background="00ffff" onscrollto="page1" onscrollaway="alert" _alert="4"></panel>
<panel name="5" width="25%" height="100%" background="0000ff" onscrollto="page1" onscrollaway="alert" _alert="5"></panel>
<panel name="6" width="25%" height="100%" background="ff0000" onscrollto="page1" onscrollaway="alert" _alert="6"></panel>
<panel name="7" width="25%" height="100%" background="ffff00" onscrollto="page1" onscrollaway="alert" _alert="7"></panel>
<panel name="8" width="25%" height="100%" background="ff00ff" onscrollto="page1" onscrollaway="alert" _alert="8"></panel>
</pager>
</panel>
</main>
<actions>
<action name="oninit" oninit="yes">
<assign property="var:page1" value="1"/>
</action>
<action name="page1">
<if lhs="[var:page1]" operator="e" rhs="1">
<alert message="1"/> THIS IS WHERE YOUR STOP SOUND ACTION GOES
<assign property="var:page1" value="0"/>
</if>
</action>
</actions>
</wire>

Hi thanks for the answer but I dont understand very well.
Why I have to put the alert on the pages?



<panel name="arpa" alias="ARPA" clip="yes" width="100%" height="100%" alpha="1" onpage="1" onscrollaway="start" _alert="1" > </panel>



In the action I putted



<action name="start" oninit="yes">
<assign property="var:page1" value="1"/>
<play action="sound1" />
</action>

<action name="sound1">
<sound action="play" source="other/arpa" type="mp3" />
</action>

<action name="page1">
<if lhs="[var:page1]" operator="e" rhs="1">
<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>
<assign property="var:page1" value="0"/>
</if>
</action>

<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>



Doesn't work :(
I am sorry if I wasn't more clear.

In your situation you do not need the _alert, you can ignore that.

You need to focus on the onscrollto action. Place an onscrollto action on any page that isn't page 1, so if a user scrolls to any page that isn't page 1 the first time it is effectively "scrolling away" from page 1. If you onscrollto any page that is not page 1 (marked by setting a variable oninit) then you should trigger your page1 action. This way your sound will only stop one time after you scroll away from page one initially. Changing the variable to zero within the if statement ensures that the action is not fired again.

I will see about getting this bug escalated so you can run the onscrollaway normally. Sorry about the inconvenience.
Thank you Ian but the sound stop and start again. Maybe is the action construction?

I've putted the onscrollto in every pages.

Here is the action. When I scroll away from page one the sound stop but after one secodn it restart...



<action name="start" oninit="yes">
<assign property="var:page1" value="1"/>
<play action="sound1" />
</action>

<action name="sound1">
<sound action="play" source="other/arpa" type="mp3" />
</action>

<action name="page1">
<if lhs="[var:page1]" operator="e" rhs="1">
<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>
<assign property="var:page1" value="0"/>
</if>
</action>

<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>

It doesn't work. I'll explore more tomorrow. Thanks.

Final action code:


<action name="start" oninit="yes">
<assign property="var:page1" value="1"/>
</action>

<action name="sound1">
<sound action="play" source="other/arpa" type="mp3" />
</action>

<action name="page1">
<if lhs="[var:page1]" operator="e" rhs="1">
<sound action="stop" source="other/arpa" type="mp3" />
<assign property="var:page1" value="0"/>
</if>
</action>

<action name="soundstop">
<sound action="stop" source="other/arpa" type="mp3" />
</action>


And the pages code...


<panel name="arpa" alias="ARPA" clip="yes" width="100%" height="100%" alpha="1" onscrollto="sound1" onpage="1"> </panel>
<panel name="panel1_2" width="50" height="50" xpos="53" ypos="672" onpage="2" onscrollto="page1" onclick="crediti" clicktarget="IMGVIEWER0" _file="graphics/crediti_page.png"> </panel>
<panel name="panel2_2" width="50" height="50" xpos="924" ypos="672" onpage="2" onclick="aiuto" clicktarget="IMGVIEWER0" _file="graphics/help_page.png"> </panel>
<panel name="panel1_3" width="50" height="50" xpos="36" ypos="90" onpage="3" onscrollto="page1" onclick="testo" clicktarget="IMGVIEWER" _file="graphics/testi/annunciazione.png"> </panel>
<panel name="panel1_4" width="50" height="50" xpos="36" ypos="90" onpage="4" onscrollto="page1" onclick="testo" clicktarget="IMGVIEWER" _file="graphics/testi/nascita.png"> </panel>
<panel name="panel1_5" width="50" height="50" xpos="36" ypos="90" onpage="5" onscrollto="page1" onclick="testo" clicktarget="IMGVIEWER" _file="graphics/testi/magi.png"> </panel>
<panel name="panel1_6" width="50" height="50" xpos="940" ypos="90" onpage="6" onscrollto="page1" onclick="testo" clicktarget="IMGVIEWER" _file="graphics/testi/battesimo.png"> </panel>
Okay, sound can be pretty tricky, so we have a best practice to use a play tag to drive the contents of the sound attributes. Check out the example below that works.

I am using a play tag with some object variables to pass data to the sound tags. This is also referenced in this topic here: https://getsatisfaction.com/rarewire/...


<wire>
<main>
<panel name="background" alias="BACKGROUND" height="100%" width="100%">
<pdf name="pdf" alias="PDF" source="constitution.pdf" height="100%" width="100%" spreads="yes" covertile="no" tile="yes" orientation="horizontal" onscrollto="page1">
<panel name="panel1_2" width="50" height="50" xpos="53" ypos="672" onpage="2" background="ff0000" onclickup="soundstop" onscrollto="page1"></panel>
<panel name="panel1_3" width="50" height="50" xpos="36" ypos="90" onpage="3" background="ffee00" onscrollto="page1" ></panel>
<panel name="panel1_4" width="50" height="50" xpos="36" ypos="90" onpage="4" onscrollto="page1"></panel>
<panel name="panel1_5" width="50" height="50" xpos="36" ypos="90" onpage="5" onscrollto="page1"></panel>
<panel name="panel1_6" width="50" height="50" xpos="940" ypos="90" onpage="6" onscrollto="page1"></panel>
</pdf>
</panel>
</main>

<actions>
<action name="start" oninit="yes">
<assign property="var:page1" value="1"/>
<play action="clip" _action="play" _source="references" _type="mp3" />
</action>

<action name="page1">
<if lhs="[var:page1]" operator="e" rhs="1">
<sync>
<play action="clip" _action="stop" _source="references" _type="mp3" />
<assign property="var:page1" value="0"/>
<alert message="STOP"/>
</sync>
</if>
</action>
<action name="clip">
<sound action="_action" source="_source" type="_type"/>
</action>
</actions>
</wire>