淡出或隐藏时停止歌曲?

时间:2013-06-15 13:11:56

标签: javascript jquery playback

我正在开发一种由HTML扩展程序支持的音乐。

一旦hide(),我如何停止播放歌曲;或者fadeOut();函数被称为?

这是HTML和PHP(是的,安全问题,仍处于开发阶段,所以我一旦修复所有安全性和错误

<?php
    require "core/database.php";

    $id = $_GET['id'];

    $select_song = mysql_query("SELECT * FROM music_player WHERE song_id='$id'") or die("we got an error");
    $retrive_song = mysql_fetch_array($select_song);
    $song_id = $retrive_song['song_id'];
    $song_path = $retrive_song['song_path'];
    $song_name = $retrive_song['song_name'];
    $band = $retrive_song['band'];
    echo($song_name);


    echo "
    <html>
    <head>
    </head>
    <script src='js/jquery.js'></script>
    <script src='js/custom.js'></script>

        <div id='content' style='display:none;'>
    <audio style=' display:block;' controls>

      <source src='music/$song_path'>
    Your browser does not support the audio element.
    </div>
    </audio>
        <b>Other Songs From $band</b>

    ";
        $select_band = mysql_query("SELECT * FROM music_player WHERE band='$band'");

        while($get_band = mysql_fetch_array($select_band)) {

        $band_song = $get_band['song_name'];
        if($song_name!=$band_song) {
    echo "
    <p> 

    <a href='#' class='songs_link'> $band_song </a> <br>

    </p>
    </html>


    ";
    }
    }

?>

这是jQuery做一些自定义更改

$(document).ready(function() {
$('#content').show();


    $('.songs_link').click(function() {

    $('#content').hide();

    });
});

我正试图淡出当前的歌曲然后转到用户选择点击链接后的新歌曲。

1 个答案:

答案 0 :(得分:0)

在音频元素中添加一个id,然后:

(...).fadeOut(function(){
   $('#audio_element').get(0).pause(); // or .stop()
});