5 Replies - 3234 Views - Last Post: 02 September 2009 - 05:02 AM Rate Topic: -----

#1 JohnorSky  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 137
  • Joined: 02-September 08

How to play next file in listview?

Post icon  Posted 01 September 2009 - 03:16 AM

I have this code to list selected media files within a Listview control to play upon double mouse click.
	Private Sub AddMusicToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddMusicToolStripMenuItem.Click
		On Error Resume Next
		Dim Multi() As String
		Dim FEn As IEnumerator
		Dim str(2) As String
		Dim itm As ListViewItem
		Dim path, Name As String
		Dim OpenDialog As New OpenFileDialog
		OpenDialog.Filter = "Supported Media (avi, mid, mp3, mpg, mpeg, mp4, wav, wma, wmv)|*.avi;*.mid;*.mp3; *.mpg; *.mpeg;*.mp4;*.wav;*.wma;*.wmv|Audio Media (*.mid, *.mp3, *.wav, *.wma|*.mid;*.mp3;*.wav;*.wma|Video Media (*.avi, *.mpg, *.mpeg, *.wmv)|*.avi;*.mpg;*.mpeg;*.wmv"
		OpenDialog.Multiselect = True
		If OpenDialog.ShowDialog = Windows.Forms.DialogResult.OK Then Multi = OpenDialog.FileNames
		If IsNothing(Multi) Then Exit Sub
		FEn = Multi.GetEnumerator
		FEn.Reset()
		While FEn.MoveNext
			str(1) = (CType(FEn.Current, String))
			path = (CType(FEn.Current, String))
			Dim x As Integer = path.LastIndexOf("\") + 1
			Dim mediaName As String = path.Substring(x)
			x = mediaName.LastIndexOf(".")
			mediaName = mediaName.Substring(0, x)
			Name = mediaName
			x = Nothing
			mediaName = Nothing
			str(0) = Name
			itm = New ListViewItem(str)
			ListView1.Visible = False
			ListView1.Items.Add(itm)
			ListView1.Visible = True
		End While
	End Sub


I would like to be able to make code to, once i select the a file in the listbox via mouse click (the code for this is below), after the file finishes playing the next file starts playing until the end of the list.
  listview1.Items(0).Selected = True
  listview1.Select()




I tried to do something like:
if (AxWindowsMediaPlayer1.playState = 1) then  listview1.Items(0).Selected = False
if (AxWindowsMediaPlayer1.playState = 1) then listview1.Items(1).Selected = True
listview1.select()
AxWindowsMediaPlayer1.URL = (ListView1.SelectedItems(0).SubItems(1).Text)


that will, if the media player is stopped, select the 'second' item in the listview and then play it... that is bound to the second item though and I made many timers and such to try and get this method to work but nothing so far works..

This post has been edited by JohnorSky: 01 September 2009 - 03:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to play next file in listview?

#2 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How to play next file in listview?

Posted 01 September 2009 - 04:35 AM

View PostJohnorSky, on 1 Sep, 2009 - 02:16 AM, said:

		On Error Resume Next



Look up error handling. That is REALLY not a good idea. Really Not A Good Idea.

View PostJohnorSky, on 1 Sep, 2009 - 02:16 AM, said:

I tried to do something like:
if (AxWindowsMediaPlayer1.playState = 1) then  listview1.Items(0).Selected = False
if (AxWindowsMediaPlayer1.playState = 1) then listview1.Items(1).Selected = True
listview1.select()
AxWindowsMediaPlayer1.URL = (ListView1.SelectedItems(0).SubItems(1).Text)


Very close:

if AxWindowsMediaPlayer1.playState = 1 Then
dim x as integer = listview1.selectedindex
listview1.items(x).selected = false
listview1.items(x + 1).selected = true
end if
listview1.select()
AxWindowsMediaPlayer1.URL = (ListView1.SelectedItems(0).SubItems(1).Text)



If I understood you correctly, that's all you should have to do (unless I messed something up, that was off the top of my head).
Was This Post Helpful? 0
  • +
  • -

#3 JohnorSky  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 137
  • Joined: 02-September 08

Re: How to play next file in listview?

Posted 01 September 2009 - 04:55 AM

It says 'Selectedindex' is not a member of 'System.Windows.Forms.ListView'
Was This Post Helpful? 0
  • +
  • -

#4 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How to play next file in listview?

Posted 02 September 2009 - 12:11 AM

View PostJohnorSky, on 1 Sep, 2009 - 03:55 AM, said:

It says 'Selectedindex' is not a member of 'System.Windows.Forms.ListView'


Sorry, as I said, top of my head. Replace 'SelectedIndex' with:
SelectedIndices(0)


I got that off the MSDN site, so will work. If not, I'll code an example by hand to try again.
Was This Post Helpful? 1
  • +
  • -

#5 JohnorSky  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 137
  • Joined: 02-September 08

Re: How to play next file in listview?

Posted 02 September 2009 - 03:33 AM

This seems to be working nicely :-), Thanks!

This post has been edited by JohnorSky: 02 September 2009 - 03:45 AM

Was This Post Helpful? 0
  • +
  • -

#6 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How to play next file in listview?

Posted 02 September 2009 - 05:02 AM

View PostJohnorSky, on 2 Sep, 2009 - 02:33 AM, said:

This seems to be working nicely :-), Thanks!


No problem! Any other questions, feel free to ask.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1