locked
Windows Media Player Control Drag and Drop RRS feed

  • Question

  •  

    The Windows Media Player Control has the AllowDrop property but there are no DragDrop or DragOver events defined?

     

    I want to be able to drag a media file onto the control and set the URL property so it will play. 

     

    The problem also exists in VB6 and the way I got around it was to place a image control over the WMP control and make sure it was on top.  I could then use the image control dragdrop event and it worked fine.  Since VB6 image controls when empty don't display and are transparent. 

     

    This does not work in VB.NET.   I have tried to use a Label control or other control and set the background color to transparent using SetStyle(ControlStyles.SupportsTransparentBackColor, True) but could still not get it to work.

     

    Any suggestions on the Drag and Drop options for the Media Player Control?

     

    Jeff

     

    Tuesday, April 15, 2008 10:52 PM

Answers

  • Well as you say DragDrop will not work so all I can suggest is a button that opens a OpenFileDialogBox or another control that will accept DragDrop . Just in case and if it might help here is some code for what I suggested . I named the media player control Player and used a listbox for draging files in from the F:\Recorded TV directory . You can click on the items in the listbox after to have them play . Maybe some of it will be usefull .

     

    Code Snippet

    Imports System.io

    Imports AxWMPLib

    Imports WMPLib

     

    Public Class Form1

     

    Dim Playlist As IWMPPlaylist = Nothing

     

    Private Sub ListBox1_DragDrop(ByVal sender As Object, _

    ByVal e As System.Windows.Forms.DragEventArgs) _

    Handles ListBox1.DragDrop

     

         Dim s() As String = e.Data.GetData("FileDrop", False)

         Dim i As Integer

     

         If Playlist Is Nothing Then

              Playlist = Player.newPlaylist("myPlayList", "")

         End If

     

         Dim AllowedTypes As String = ".dvr-ms .avi .mp3 .wav"

         For i = 0 To s.Length - 1

              If AllowedTypes.Contains(Path.GetExtension(s(i))) Then

                   ListBox1.Items.Add(Path.GetFileName(s(i)))

                   Playlist.appendItem(Player.newMedia(s(i)))

              End If

         Next i

         Player.currentPlaylist = Playlist

         Player.Ctlcontrols.play()

    End Sub

     

    Private Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter

         If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then

              e.Effect = DragDropEffects.All

         Else

              e.Effect = DragDropEffects.None

         End If

    End Sub

     

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

         Try

              For x As Integer = 0 To Player.currentPlaylist.count - 1

                   If Player.currentPlaylist.Item(x).sourceURL = Path.Combine     ("F:\RecordedTV", ListBox1.SelectedItem) Then

                        Player.Ctlcontrols.playItem(Player.currentPlaylist.Item(x))

                        Exit For

                   End If

              Next

         Catch ex As Exception

              MessageBox.Show(ex.Message, "", MessageBoxButtons.OK)

         End Try

     

    End Sub

    End Class

     

     

    Wednesday, April 16, 2008 5:56 PM

All replies

  • Dock a splitcontainer on your form and then dock the media player in the left panel . Use the right panel for your drag and drop to create a playlist .
    Wednesday, April 16, 2008 9:32 AM
  • I don't want to create a playlist.   I want to be able to drag a file from a open folder of content (MP3, WMV, MPEG, etc) onto the MediaPlayer control in my VB application and have it start playing.

     

    I want to have the WindowsMediaPlayer control allow droping and then in the DragDrop event I want to set the URL property  to the filename of the dragged file.

     

     

     

    Wednesday, April 16, 2008 4:31 PM
  • Well as you say DragDrop will not work so all I can suggest is a button that opens a OpenFileDialogBox or another control that will accept DragDrop . Just in case and if it might help here is some code for what I suggested . I named the media player control Player and used a listbox for draging files in from the F:\Recorded TV directory . You can click on the items in the listbox after to have them play . Maybe some of it will be usefull .

     

    Code Snippet

    Imports System.io

    Imports AxWMPLib

    Imports WMPLib

     

    Public Class Form1

     

    Dim Playlist As IWMPPlaylist = Nothing

     

    Private Sub ListBox1_DragDrop(ByVal sender As Object, _

    ByVal e As System.Windows.Forms.DragEventArgs) _

    Handles ListBox1.DragDrop

     

         Dim s() As String = e.Data.GetData("FileDrop", False)

         Dim i As Integer

     

         If Playlist Is Nothing Then

              Playlist = Player.newPlaylist("myPlayList", "")

         End If

     

         Dim AllowedTypes As String = ".dvr-ms .avi .mp3 .wav"

         For i = 0 To s.Length - 1

              If AllowedTypes.Contains(Path.GetExtension(s(i))) Then

                   ListBox1.Items.Add(Path.GetFileName(s(i)))

                   Playlist.appendItem(Player.newMedia(s(i)))

              End If

         Next i

         Player.currentPlaylist = Playlist

         Player.Ctlcontrols.play()

    End Sub

     

    Private Sub ListBox1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter

         If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then

              e.Effect = DragDropEffects.All

         Else

              e.Effect = DragDropEffects.None

         End If

    End Sub

     

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

         Try

              For x As Integer = 0 To Player.currentPlaylist.count - 1

                   If Player.currentPlaylist.Item(x).sourceURL = Path.Combine     ("F:\RecordedTV", ListBox1.SelectedItem) Then

                        Player.Ctlcontrols.playItem(Player.currentPlaylist.Item(x))

                        Exit For

                   End If

              Next

         Catch ex As Exception

              MessageBox.Show(ex.Message, "", MessageBoxButtons.OK)

         End Try

     

    End Sub

    End Class

     

     

    Wednesday, April 16, 2008 5:56 PM
  • Hello,

     

    How can i add a song to a existing playlist. For example in listview1 i have playlist test.wpl from other listview2, where is lets say top40.wpl, i add a song to test.wpl, listview1, and test.wpl is saved with new added song.

     

    Thank you sir for your time.

     

    Regards,

     

    Rocky

    Sunday, May 11, 2008 12:52 PM