[ VB .Net Event Handeling ] (1 Viewer)

kyleh0000

MP Donator
  • Premium Supporter
  • April 28, 2009
    144
    23
    Home Country
    Hi All,

    Im after a bit of help making a plugin, first of im writing this one in vb .net and its a JukeBox Plugin.

    The idea of it is to implement something similar to the XBMC party mode, except with a few more features and some other stuff

    anyway, im looking for a way to do load some code each time a song is changed.

    I have been having a look at the doco and also have the latest SVN which I have been searching over to try and find some examples, and i have found what im after but as its in C# it doesnt translate well to vb .net ( I have tried a few of the websites that convert it for you with no luck)

    Here is the code i have so far below, nothing is underlined as wrong in visual studio and no errors appear in the log, its just the messagebox doesnt show up when the song is changed.

    WithEvents eClass As MediaPortal.Player.g_Player

    Public Sub test(ByVal type As g_Player.MediaType, ByVal filename As String) Handles eClass.PlayBackStarted

    MsgBox(filename)
    End Sub

    The idea is to have a small playlist say 5 songs or something and everytime the current song is changed it removes the current song from the play list and adds another random song, this part im sure i can do its just getting it to trigger the code.

    When I change song in MP i can see the g_Player.PlayBackStarted event in the logs but like i said i dont get the message box pop up so its not doing anything.

    Any help getting this up and running is much apreaciated :D
     

    DJBlu

    Portal Pro
    August 14, 2007
    1,670
    813
    Llanelli
    Home Country
    United Kingdom United Kingdom
    Try this

    dim dlg as new GUIDialogOK = GUIWindowManager.GetWindow(GUIWindow.Window.WINDOW_DIALOG_OK)
    dlg.SetHeading("Window Title")
    dlg.SetLine(1, "Playing")
    dlg.SetLine(2, filename)
    dlg.DoModal(GUIWindowManager.ActiveWindow)

    If this doesn't work then post the code you need converting and I'll convert it. As long as its not 4000 lines. :D
     

    kyleh0000

    MP Donator
  • Premium Supporter
  • April 28, 2009
    144
    23
    Home Country
    Hi Thanks for the quick reply :)

    Maybe you miss understood what im wanting to do.

    Basicly i want to create a process plugin that each time the player changes media it executes a part of my code, I belive the C# for this is locate within the below code, in particualr the first part (i dont need all the other stuff just really the first few lines)

    What the C# codes does is each time the event g_Player.PlaybackStarted is triggered from within MePo it run the OnPlaybackStarted Sub. The below code is taken from MePo's Audioscrobbler plugin.

    public void Start()
    {
    string currentUser = String.Empty;
    _alertTime = INFINITE_TIME;

    GUIWindowManager.OnNewAction += new OnActionHandler(OnNewAction);
    g_Player.PlayBackStarted += new g_Player.StartedHandler(OnPlayBackStarted);
    g_Player.PlayBackEnded += new g_Player.EndedHandler(OnPlayBackEnded);
    g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnPlayBackStopped);

    using (Settings xmlreader = new MPSettings())
    {
    currentUser = xmlreader.GetValueAsString("audioscrobbler", "user", String.Empty);
    _announceNowPlaying = xmlreader.GetValueAsBool("audioscrobbler", "EnableNowPlaying", true);
    }

    MusicDatabase mdb = MusicDatabase.Instance;
    _doSubmit = (mdb.AddScrobbleUserSettings(Convert.ToString(mdb.AddScrobbleUser(currentUser)), "iSubmitOn", -1) == 1)
    ? true
    : false;

    Log.Info("Audioscrobbler plugin: Submit songs: {0}, announce Now Playing: {1}", Convert.ToString(_doSubmit),
    Convert.ToString(_announceNowPlaying));

    if (_doSubmit)
    {
    OnManualConnect(null, null);
    }
    }

    From what i understand the code you posted will create a messagebox is that right?
     

    DJBlu

    Portal Pro
    August 14, 2007
    1,670
    813
    Llanelli
    Home Country
    United Kingdom United Kingdom
    Public Sub Start()
    Dim currentUser As String = String.Empty
    _alertTime = INFINITE_TIME

    GUIWindowManager.OnNewAction += New OnActionHandler(OnNewAction)
    g_Player.PlayBackStarted += New g_Player.StartedHandler(OnPlayBackStarted)
    g_Player.PlayBackEnded += New g_Player.EndedHandler(OnPlayBackEnded)
    g_Player.PlayBackStopped += New g_Player.StoppedHandler(OnPlayBackStopped)

    Using xmlreader As Settings = New MPSettings()
    currentUser = xmlreader.GetValueAsString("audioscrobbler", "user", [String].Empty)
    _announceNowPlaying = xmlreader.GetValueAsBool("audioscrobbler", "EnableNowPlaying", True)
    End Using

    Dim mdb As MusicDatabase = MusicDatabase.Instance
    _doSubmit = false
    If(mdb.AddScrobbleUserSettings(Convert.ToString(mdb.AddScrobbleUser(currentUser)), "iSubmitOn", -1) = 1) then
    _doSubmit = true
    end if


    Log.Info("Audioscrobbler plugin: Submit songs: {0}, announce Now Playing: {1}", Convert.ToString(_doSubmit), Convert.ToString(_announceNowPlaying))

    If _doSubmit Then
    OnManualConnect(Nothing, Nothing)
    End If
    End Sub
     

    kyleh0000

    MP Donator
  • Premium Supporter
  • April 28, 2009
    144
    23
    Home Country
    thanks for the reply, that code is a basically the same as what the web converter gave me, but unfortunately it doesn't work

    on the g_Player.PlayBackStart i get an underline and it tells me this is an event and it should be called with Raise event

    also on the g_Player.StartedHandler(OnPlayBackStarted) i get an error telling me StartedHandler requires an AddressOf Arguement or lambda expression

    i think the original code is pretty close to what i need i just cant figure out how to start the handler, but i keep getting the error about how it requires and AddressOf argument

    WithEvents eClass As MediaPortal.Player.g_Player

    Public Sub test(ByVal type As g_Player.MediaType, ByVal filename As String) Handles eClass.PlayBackStarted

    MsgBox(filename)
    End Sub

    thanks heeps for you help hopefully we can get it working, i know there is a way to do it, its just finding it :)
     

    DJBlu

    Portal Pro
    August 14, 2007
    1,670
    813
    Llanelli
    Home Country
    United Kingdom United Kingdom
    Code:
    Imports System
    Imports System.Windows.Forms
    Imports MediaPortal.GUI.Library
    Imports MediaPortal.Dialogs
    
    Public Class Plugin
        Implements IPlugin
        Implements ISetupForm
    
        Public Sub Start() Implements IPlugin.Start
            Log.Info("Started and Added Handler")
            AddHandler MediaPortal.Player.g_Player.PlayBackChanged, AddressOf PlayBackChanged
        End Sub
        Public Sub PlayBackChanged(ByVal type As MediaPortal.Player.g_Player.MediaType, ByVal stoptime As Integer, ByVal filename As String)
            Dim dlg As GUIDialogOK = GUIWindowManager.GetWindow(GUIWindow.Window.WINDOW_DIALOG_OK)
            dlg.SetHeading("Window Title")
            dlg.SetLine(1, "Last Song was")
            dlg.SetLine(2, filename)
            dlg.DoModal(GUIWindowManager.ActiveWindow)
        End Sub
        Public Sub [Stop]() Implements IPlugin.Stop
            RemoveHandler MediaPortal.Player.g_Player.PlayBackChanged, AddressOf PlayBackChanged
            Log.Debug("Removed Handler")
    
        End Sub
    
        Public Function Author() As String Implements MediaPortal.GUI.Library.ISetupForm.Author
            Return "Your_Name"
        End Function
    
        Public Function CanEnable() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.CanEnable
            Return True
        End Function
    
        Public Function DefaultEnabled() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.DefaultEnabled
            Return True
        End Function
    
        Public Function Description() As String Implements MediaPortal.GUI.Library.ISetupForm.Description
            Return "Description"
        End Function
    
        Public Function GetHome(ByRef strButtonText As String, ByRef strButtonImage As String, ByRef strButtonImageFocus As String, ByRef strPictureImage As String) As Boolean Implements MediaPortal.GUI.Library.ISetupForm.GetHome
    
        End Function
    
        Public Function GetWindowId() As Integer Implements MediaPortal.GUI.Library.ISetupForm.GetWindowId
            Return 1000000
        End Function
    
        Public Function HasSetup() As Boolean Implements MediaPortal.GUI.Library.ISetupForm.HasSetup
            Return False
        End Function
    
        Public Function PluginName() As String Implements MediaPortal.GUI.Library.ISetupForm.PluginName
            Return "Test"
        End Function
    
        Public Sub ShowPlugin() Implements MediaPortal.GUI.Library.ISetupForm.ShowPlugin
    
        End Sub
    End Class

    This works. I have just tested it.

    Make sure you put your plugin in the process folder.
     

    Users who are viewing this thread

    Top Bottom