質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
VB

VB(ビジュアルベーシック)はマイクロソフトによってつくられたオブジェクト指向プログラミング言語のひとつで、同社のQuickBASICが拡張されたものです。VB6の進化版といわれています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

VB.NET

Microsoft Visual Basic .NETのことで、Microsoft Visual Basic(VB6)の後継。 .NET環境向けのプログラムを開発することができます。 現在のVB.NETでは、.NET Frameworkを利用して開発を行うことが可能です。

Q&A

解決済

1回答

410閲覧

サイトにあったplayerの事について

退会済みユーザー

退会済みユーザー

総合スコア0

VB

VB(ビジュアルベーシック)はマイクロソフトによってつくられたオブジェクト指向プログラミング言語のひとつで、同社のQuickBASICが拡張されたものです。VB6の進化版といわれています。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

VB.NET

Microsoft Visual Basic .NETのことで、Microsoft Visual Basic(VB6)の後継。 .NET環境向けのプログラムを開発することができます。 現在のVB.NETでは、.NET Frameworkを利用して開発を行うことが可能です。

0グッド

1クリップ

投稿2018/04/21 11:27

編集2018/04/25 11:18

こんばんは。
サイトにあった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
サイトのプロジェクト使用しています。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

syameimaru

2018/04/23 05:25 編集

DLLやサンプルをダウンロードして再現しようとしたのですが、DLLが原因と思われるエラーが発生しました。libzplayにはバージョンが幾つかあると思うのですが、そちらはどのバージョンのものを使用していますか?
退会済みユーザー

退会済みユーザー

2018/04/23 05:47

syameimaruさん。Libzplayのバージョンは2.0.2です。dllファイルはC:\Users\User\Documents\Visual Studio 2017\Projects\プロジェクト名\プロジェクト名\bin\Debug\Libzplay.dllここいれてます。少し内容を編集します。
syameimaru

2018/04/23 05:48

32bitで動作させてみたところ上手くいきました。ありがとうございます。
guest

回答1

0

ベストアンサー

複数選択を許可するだけであれば
OpenFileDialog1.Multiselect = True
を起動時に評価されるようにすれば大丈夫です。
複数開く場合...とありますが
OpenFileDialog1.FileNameをOpenFileDialog1.FileNamesに変更し(複数のファイル名を取得できるようになります)、それを配列か何かに入れてそれをリストボックスに入れるなりすればいけると思います。
もちろん受け取っただけなので、[Add file]のボタンの動作を参考にしてそれぞれ追加処理をする必要があります。

追記:


OpenFileDialog1.FileNames.Lengthで複数選択された場合
選択された個数を取得できます。


dim val as integer = OpenFileDialog1.FileNames.Length
OpenFileDialog1.FileNames(val)で指定されたvalの値の位置のファイル名を取得できます。

投稿2018/04/23 06:06

編集2018/04/23 06:15
syameimaru

総合スコア181

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2018/04/23 06:38

ありがとうございます。 試してみます。
退会済みユーザー

退会済みユーザー

2018/04/23 07:22

すいません 試しにやった所エラーが発生しました。 OpenFileDialog1.FileNamesに変更しましたら以下のエラー ”BC30311 型 'String()' の値を 'String' に変換できません。"
syameimaru

2018/04/23 07:51 編集

OpenFileDialog1.FileNamesを変数に入れる場合は、配列に入れてください
syameimaru

2018/04/23 07:53 編集

If Not (player.OpenFile(OpenFileDialog1.FileNames, TStreamFormat.sfAutodetect)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If でエラーが発生していると仮定して player.OpenFileでは配列は扱えないので、追記にも書いたとおり、 OpenFileDialog1.FileNames.Lengthで選択された個数を取得し、 その個数分For文で If Not (player.OpenFile(OpenFileDialog1.FileNames(val), TStreamFormat.sfAutodetect)) Then MessageBox.Show(player.GetError(), String.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If ※(val)はOpenFileDialog1.FileNames.Length これを回せばいけると思います。
退会済みユーザー

退会済みユーザー

2018/04/24 10:27 編集

syameimaruさん ありがとうございます。 申し訳ございませんでした。 ダウンロードしたプロジェクトから使用した物をリストとテキストボックス追加しました。 すいませんでした。
syameimaru

2018/04/24 00:22

すみませんが、情報が少なすぎます。 TrC00は普通のリストボックスですか?継承したコントロールですか? 選択したらエラーになりました...とありますがエラーの詳細はどうなっていますか? このまま実行しても[OpenFileDialog3.FileName]には何も入らないのでNULLか空白文字を追加することになりますが大丈夫でしょうか? [OpenFileDialog3.FileName]を別の場所で取得しているなら、エラーが起きないようにしっかりと処理してから取得していますか?(複数選択されていないか、そのファイルが実際に存在するかなど) おそらく上記以外にもコードやコントロールが追加されているのでしょう... 私がその分のコードとコントロールを自作すればいい話なのですが、kon11cさんと同じコードやコントロールになるとは限らないので(同じ環境でやらないと、発生したエラーもこちらで再現できないため)、もう少し情報をください。
退会済みユーザー

退会済みユーザー

2018/04/25 11:24

すいませんでした。 内容を修正しました。 リストボックスを選択 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() End Sub Dim a As String() Dim file As String() Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk 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)) 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 End If showinfo() player.StartPlayback() End Sub 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
退会済みユーザー

退会済みユーザー

2018/04/25 12:01

ファイルを開いたら複数選択出来ましたが、リストボックスを選択するのは 可能になったんですけど(以前の投稿したコードを使ってます) リストボックスを選択するとテキストボックスに(複数)表示が変わります。 複数ある場合に他のファイルを選択すると他の曲が再生したいと思ってますが、いろいろ調べてやってみたんですがどうもうまく行かないです。 試しに 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 '試しにやった結果 player.AddFile(OpenFileDialog1.FileName(a(ListBox1.SelectedIndex)), TStreamFormat.sfAutodetect) Timer1.Start() Timer2.Start() player.StartPlayback() End Sub debug中のエラー 'Integer' への変換は無効です。 Source=Microsoft.VisualBasic スタック トレース: 場所 Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) 内部例外 1: FormatException: 入力文字列の形式が正しくありません。 いろいろご迷惑をおかけして申し訳ございません プロジェクトの追加したlibZPlay.vbのコードも追加しないとリストボックスを選択したら他の曲が再生するように追加しないとダメなんでしょうか? Axwindowsmediaplayer1.URL=a(Listbox1.SelectIndex)で出来るけど 追加したZplayerはクラス、メリットがないので 選択した後の曲が再生するようにしたいです。 情報不足してすいませんでした。
syameimaru

2018/04/26 02:05 編集

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged ’If ListBox1.SelectedItem <> "" Then If ListBox1.SelectedItem IsNot ""Then TextBox1.Text = System.IO.Path.GetFileName(ListBox1.SelectedItem.ToString) Else Exit Sub End If If IntSelectIndexPre = ListBox1.SelectedIndex Then Exit Sub End If IntSelectIndexPre = ListBox1.SelectedIndex player.Close() player.OpenFile(a(IntSelectIndexPre), TStreamFormat.sfAutodetect) showinfo() player.StartPlayback() End Sub だとおもいます。 あと度々でてくる「メリット」という単語は「メソッド」の間違いですかね...?
退会済みユーザー

退会済みユーザー

2018/04/26 09:34

syameimaruさん 本当にありがとうございました。 メリットじゃなく、メリッドです(字間違い多くってすいませんでした。) コードの方は無事出来ました。感謝いたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問