Playing a one time sound in mchat

Support area for phpBB's mChat extension
User avatar
wads24
Donor
Posts: 10
Joined: 26 Aug 2018, 02:16
Location: Boise Idaho
Contact:

Playing a one time sound in mchat

#1

Post by wads24 » 16 Oct 2018, 20:49

I have a welcome to chat mp3 sound that I would like to play one per session.

How would I do this?

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Playing a one time sound in mchat

#2

Post by kasimi » 16 Oct 2018, 20:55

Add this to mchat_body.html at the top:

Code: Select all

{% if user.data.is_registered and not user.data.session_admin and user.time_now - user.data.session_start < 3 %}
    <audio class="hidden" src="URL.mp3" autoplay></audio>
{% endif %}
It will only work if mChat is displayed on the first page after logging in.

kaptangula
Posts: 1
Joined: 17 Oct 2018, 07:47

Re: Playing a one time sound in mchat

#3

Post by kaptangula » 17 Oct 2018, 07:50

mod help

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Playing a one time sound in mchat

#4

Post by kasimi » 17 Oct 2018, 08:04

What is it that you need help with?

User avatar
wads24
Donor
Posts: 10
Joined: 26 Aug 2018, 02:16
Location: Boise Idaho
Contact:

Re: Playing a one time sound in mchat

#5

Post by wads24 » 18 Oct 2018, 19:29

kasimi wrote:
16 Oct 2018, 20:55
Add this to mchat_body.html at the top:

Code: Select all

{% if user.data.is_registered and not user.data.session_admin and user.time_now - user.data.session_start < 3 %}
    <audio class="hidden" src="URL.mp3" autoplay></audio>
{% endif %}
It will only work if mChat is displayed on the first page after logging in.
Awesome sauce! Thanks! It worked great

User avatar
wads24
Donor
Posts: 10
Joined: 26 Aug 2018, 02:16
Location: Boise Idaho
Contact:

Re: Playing a one time sound in mchat

#6

Post by wads24 » 26 Nov 2018, 15:15

kasimi wrote:
16 Oct 2018, 20:55
Add this to mchat_body.html at the top:

Code: Select all

{% if user.data.is_registered and not user.data.session_admin and user.time_now - user.data.session_start < 3 %}
    <audio class="hidden" src="URL.mp3" autoplay></audio>
{% endif %}
It will only work if mChat is displayed on the first page after logging in.
Will this work for a "You got a Private Message" mp3 file also?

User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Playing a one time sound in mchat

#7

Post by kasimi » 08 Dec 2018, 09:20

This requires some JavaScript. Add this to your overall_footer.html. Not tested.

Code: Select all

{% if user.data.is_registered %}
    <audio class="last-pm-sound hidden" src="URL.mp3"></audio>
    <script>
    (function() {
        if (typeof localStorage !== 'object') {
            return;
        }
        var localLastPmSound = parseInt(localStorage.getItem('lastPmSound'));
        var remoteLastPmSound = {{ user.data.user_last_privmsg }};
        if (localLastPmSound && remoteLastPmSound > localLastPmSound) {
            document.querySelector('.last-pm-sound').play();
        }
        localStorage.setItem('lastPmSound', remoteLastPmSound);
    })();
    </script>
{% endif %}

User avatar
wads24
Donor
Posts: 10
Joined: 26 Aug 2018, 02:16
Location: Boise Idaho
Contact:

Re: Playing a one time sound in mchat

#8

Post by wads24 » 08 Dec 2018, 23:02

Thanks. I'll test it

User avatar
wads24
Donor
Posts: 10
Joined: 26 Aug 2018, 02:16
Location: Boise Idaho
Contact:

Re: Playing a one time sound in mchat

#9

Post by wads24 » 09 Dec 2018, 02:26

Got error below.. I did clear cache

Code: Select all

Fatal error: Uncaught Twig_Error_Syntax: Unexpected "user" tag (expecting closing tag for the "if" tag defined near line 119). in /styles/prosilver/template/overall_footer.html:126 Stack trace: #0 /vendor/twig/twig/lib/Twig/TokenParser/If.php(36): Twig_Parser->subparse(Array) #1 /vendor/twig/twig/lib/Twig/Parser.php(192): Twig_TokenParser_If->parse(Object(Twig_Token)) #2 /vendor/twig/twig/lib/Twig/Parser.php(105): Twig_Parser->subparse(NULL, false) #3 /vendor/twig/twig/lib/Twig/Environment.php(716): Twig_Parser->parse(Object(Twig_TokenStream)) #4 /vendor/twig/twig/lib/Twig/Environment.php(774): Twig_Environment->parse(Object(Twig_TokenStream)) #5 /vendor/twig/twig/lib/Twig/Environment.php(452): Twig_Environment->compileSource( in /styles/prosilver/template/overall_footer.html on line 126


User avatar
kasimi
mChat developer
Posts: 795
Joined: 06 Oct 2016, 09:56
Location: Germany
Contact:

Re: Playing a one time sound in mchat

#10

Post by kasimi » 09 Dec 2018, 10:33

I updated the code, try again. :+1:

Post Reply

Who is online

Users browsing this forum: Xcalibr8 and 1 guest