Home » Jquery » javascript – Can I Implement to autoplay an audio file using Pusher Real Time

javascript – Can I Implement to autoplay an audio file using Pusher Real Time

Posted by: admin February 22, 2020 Leave a comment

Questions:

Is it possible to play an audio file automatically when I send data using Pusher?

$("#sound_tag").get(0).play();
$(document).ready(function(){
            // CALL FUNCTION SHOW PRODUCT
            

            show_product();

            // Enable pusher logging - don't include this in production
            Pusher.logToConsole = true;
 
            var pusher = new Pusher('e1b363d24b7d8f6b4f70', {
                cluster: 'ap1',
                forceTLS: true
            });
 
            var channel = pusher.subscribe('my-channel');
            channel.bind('my-event', function(data) {
                if(data.message === 'success'){
                    show_product();
                    //voice_message();
                }
            });

 
            // FUNCTION SHOW PRODUCT
            function show_product(){
                $.ajax({
                    url   : '<?php echo site_url("Main/get_display");?>',
                    type  : 'GET',
                    async : true,
                    dataType : 'json',
                    success : function(data){


                        var html = '';
                        var count = 1;
                        var i;
                        for(i=0; i<data.length; i++){
                            html += '<tr>'+
                                    '<td hidden="true">'+ count++ +'</td>'+
                                    '<td hidden="true">'+ data[i].ticket_id +'</td>'+
                                    '<td style="text-align: center; background-color: black;"><strong style="font-size: 97px; font-weight: bold; color: yellow; font-family:verdana; "><p style="font-size: 20px;">Ticket No.</p>'+ data[i].ticket_no +'</strong></td>'+
                                    '<td style="text-align: center; background-color: black;"><strong style="font-size: 97px; font-weight: bold; color: yellow; font-family:verdana; ">'+ data[i].proceed_to +'</strong></td>'+
                                    '</tr>';
                        }
                        $('.show_product').html(html);
                        $("#sound_tag").get(0).play();
                    }
 
                });

            }
        });
How to&Answer: