Hallo Forum
Ich habe folgendes Problem:
Auf meiner Website habe ich auf der MasterPage eine Audio-Wiedergabe, welche funktioniert. das Problem ist nun, das bei jedem Wechsel der Seite das Audio-File neu gestartet wird. Wie kann ich das beheben ?
unten der Code zum Audio Control
und der Code behind
Ich habe folgendes Problem:
Auf meiner Website habe ich auf der MasterPage eine Audio-Wiedergabe, welche funktioniert. das Problem ist nun, das bei jedem Wechsel der Seite das Audio-File neu gestartet wird. Wie kann ich das beheben ?
unten der Code zum Audio Control
HTML-Quellcode
- <audio id="audioPlayer" style="height:20px; width:450px;" autoplay src="<%=SongToPlay %>" controls onended="audioPlayerOnEnded()">Your browser does not support the Audio element.</audio>
- <asp:Label ID="Label1" runat="server" Text=" You listen to " Style="font-size:20px;border:none;font-family :Lucida Sans Unicode;"></asp:Label>
- <asp:DropDownList ID="lbAllSongs" runat="server" AutoPostBack="true" Style="font-size:20px;border:none;font-family :Lucida Sans Unicode; background-color:transparent;"></asp:DropDownList> <asp:Label ID="lblSelectedSong" runat="server" Visible="false"></asp:Label>
und der Code behind
VB.NET-Quellcode
- Public SongToPlay As String
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
- Select Case Page.Title
- Case "Home"
- Menu1.Visible = True
- Menu1.Items(0).Selected = True
- Case "Tickets"
- Menu1.Visible = True
- Menu1.Items(1).Selected = True
- Case "Fotogalerie"
- Menu1.Visible = True
- Menu1.Items(2).Selected = True
- Case "Video"
- Menu1.Visible = True
- Menu1.Items(3).Selected = True
- Case "Admin"
- Menu1.Visible = False
- End Select
- If Not IsPostBack Then
- Dim pathLocal As String
- Dim pathSongs As String
- pathLocal = Server.MapPath("~/Video")
- pathSongs = pathLocal & "/Audio/"
- Dim MyFile, MyPath As String
- MyPath = pathSongs
- MyFile = FileSystem.Dir(pathSongs & "\*.mp3")
- While MyFile <> ""
- lbAllSongs.Items.Add(MyFile)
- MyFile = FileSystem.Dir()
- End While
- lbAllSongs.SelectedIndex = 0
- SongToPlay = "../Video/Audio/" & lbAllSongs.SelectedItem.Text
- Else
- If Request.Form("__EVENTTARGET") = "audioPlayer" Then
- audioPlayerOnEnded()
- Else
- lblSelectedSong.Text = lbAllSongs.SelectedItem.Text
- SongToPlay = "../Video/Audio/" & lbAllSongs.SelectedItem.Text
- End If
- End If
- End Sub
- Protected Sub audioPlayerOnEnded()
- Dim nextIndex As Integer = findNextIndex()
- lbAllSongs.SelectedIndex = nextIndex
- lblSelectedSong.Text = lbAllSongs.SelectedItem.Text
- SongToPlay = "../Video/Audio/" & lbAllSongs.SelectedItem.Text
- End Sub
- Private Function findNextIndex() As Integer
- Dim current As Integer = lbAllSongs.SelectedIndex
- Dim nextIndex As Integer
- If current + 1 > lbAllSongs.Items.Count - 1 Then
- nextIndex = 0
- Else
- nextIndex = current + 1
- End If
- Return nextIndex
- End Function
Am lernen...