こんばんは。
サイトにあったplayerを追加しました。
##参考にあったサイト名:ZPlay VB.NET Class interface
http://libzplay.sourceforge.net/ZPLAYINTERFACE_VBNET.html
こちらのPlayerを追加したんですか、ちょっとお出すねしたい事があります。
##教えてほしい事
リストボックスを選択すると再生したい
Imports MI_LIBZPLAY_AUDIO.libZPlay Public Class Form1 Private player As ZPlay Private LoadMode As Integer Private ReverseMode As Boolean Private Echo As Boolean Private VocalCut As Boolean = False Private SideCut As Boolean = False Private NextSong As Boolean = False Private FadeFinished As Boolean = False ' need this for managed stream Private fStream As System.IO.FileStream = Nothing Private br As System.IO.BinaryReader = Nothing Private BufferCounter As Integer Private CallbackFunc As TCallbackFunc Private BlockSlideLeft As Boolean = False Private BlockSlideRight As Boolean = False ''' <summary> ''' Text callback ''' </summary> ''' <param name="text"></param> ''' <remarks></remarks> ''' Public Delegate Sub SetTextCallback(ByVal text As String) 'addfileopenfiledialog複数開けます。 Dim a As String() Dim file As String() Private Sub Button18_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click LoadMode = 3 OpenFileDialog1.FileName = "" OpenFileDialog1.Multiselect = True OpenFileDialog1.Title = "開くファイルを指定" OpenFileDialog1.Filter = "All Supported Files|*.mp3;*.mp2;*.mp1;*.ogg;*.oga;*.flac;*.wav;*.ac3;*.aac|Mp3 Files|*.mp3|Mp2 Files|*.mp2|Mp1 Files|*.mp1|Ogg Files|*.ogg|FLAC files|*.flac|Wav files|*.wav|AC-3|*.ac3|AAC|*.aac" OpenFileDialog1.FilterIndex = 1 OpenFileDialog1.RestoreDirectory = True If OpenFileDialog1.ShowDialog() = DialogResult.OK Then file = OpenFileDialog1.SafeFileNames a = OpenFileDialog1.FileNames For b As Integer = 0 To file.Length - 1 ListBox1.Items.Add(file(b)) Next ListBox1.SelectedIndex = 0 TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem) End If End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk OpenFileDialog1.Multiselect = True If LoadMode = 0 Then player.Close() If Not (player.OpenFile(OpenFileDialog1.FileName, TStreamFormat.sfAutodetect)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If ElseIf LoadMode = 1 Then player.Close() Dim format As TStreamFormat = player.GetFileFormat(OpenFileDialog1.FileName) Dim fInfo As New System.IO.FileInfo(OpenFileDialog1.FileName) Dim numBytes As Long = fInfo.Length Dim fStream As New System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read) Dim br As New System.IO.BinaryReader(fStream) Dim stream_data() As Byte = Nothing stream_data = br.ReadBytes(CInt(Fix(numBytes))) If Not (player.OpenStream(True, False, stream_data, CUInt(numBytes), format)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) End If br.Close() fStream.Close() ElseIf LoadMode = 2 Then player.Close() Dim format As TStreamFormat = player.GetFileFormat(OpenFileDialog1.FileName) BufferCounter = 0 Dim fInfo As New System.IO.FileInfo(OpenFileDialog1.FileName) Dim numBytes As UInteger = CUInt(fInfo.Length) If br IsNot Nothing Then br.Close() End If If fStream IsNot Nothing Then fStream.Close() End If br = Nothing fStream = Nothing fStream = New System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read) br = New System.IO.BinaryReader(fStream) Dim stream_data() As Byte = Nothing Dim small_chunk As UInteger = 0 small_chunk = CType(Math.Min(100000, numBytes), UInteger) ' read small chunk of data stream_data = br.ReadBytes(CInt(Fix(small_chunk))) ' open stream If Not (player.OpenStream(True, True, stream_data, CUInt(stream_data.Length), format)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) End If ' read more data and push into stream stream_data = br.ReadBytes(CInt(Fix(small_chunk))) player.PushDataToStream(stream_data, CUInt(stream_data.Length)) 'リストボックスとテキストボックス追加しました。 'リストボックスとテキストボックスに表示されます。(ボタン18) ElseIf LoadMode = 3 Then If Not (player.AddFile(OpenFileDialog1.FileName, TStreamFormat.sfAutodetect)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If showinfo() player.StartPlayback() End Sub '曲を選択、リスト選択可能※ Dim IntSelectIndexPre As Integer = 0 Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedItem <> "" Then TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem) End If If IntSelectIndexPre = ListBox1.SelectedIndex Then Exit Sub End If IntSelectIndexPre = ListBox1.SelectedIndex Timer1.Start() Timer2.Start() End Sub ’再生 Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click player.StartPlayback() End Sub Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click player.PausePlayback() End Sub Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click player.ResumePlayback() End Sub Private Sub Button5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.Click player.StopPlayback() End Sub End Class
##追加したコードの動作結果
開いたらリストボックスとテキストボックスに表示されました。
開いたファイルを選択すると曲を再生したいですが※の部分に
Dim IntSelectIndexPre As Integer = 0 Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged If ListBox1.SelectedItem <> "" Then TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem) End If If IntSelectIndexPre = ListBox1.SelectedIndex Then Exit Sub End If IntSelectIndexPre = ListBox1.SelectedIndex '※ Timer1.Start() Timer2.Start() player.StartPlayback()
##試した結果
※の部分
player.AddFile(a(ListBox1.SelectedIndex), TStreamFormat.sfAutodetect)
いろいろ試してやった所全くリストボックスを選択はされるんですが、選択後の
再生がしないので無理なんでしょうか?
お願いします。
##開発バージョン
Vistual Studio2017 VB
サイトのプロジェクト使用しています。
回答1件
あなたの回答
tips
プレビュー