Author Topic: NowPlayingList_PlayNow not working  (Read 2681 times)

stax76

  • Jr. Member
  • **
  • Posts: 28
            Case NotificationType.TagsChanging
                Try
                    Dim nowPlayingrating = CInt(mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Rating))

                    If nowPlayingrating < 3 Then
                        Dim currentIndex = mbApiInterface.NowPlayingList_GetCurrentIndex()
                        Dim nextURL = mbApiInterface.NowPlayingList_GetListFileUrl(currentIndex + 1)
                        mbApiInterface.NowPlayingList_PlayNow(nextURL)
                    End If
                Catch ex As Exception
                End Try

I'm trying now for an hour to achieve something that seems very easy, I have keyboard shortcuts to rate the currently playing track, now when I rate it 0-2 I want to play the next track, my url for the next track is fine, what happens is playback freezes.

stax76

  • Jr. Member
  • **
  • Posts: 28
I also tried mbApiInterface.Player_PlayNextTrack() which freezes also, I enabled .NET 4.5 to use the Task API making it easy to sleep a seconds, this finally has worked.

    Public Sub ReceiveNotification(sourceFileUrl As String, type As NotificationType)
        Try
            Select Case type
                Case NotificationType.TagsChanging
                    Dim nowPlayingRating = CInt(mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Rating))
                    If nowPlayingRating < 3 Then PlayNext()
            End Select
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Async Sub PlayNext()
        Await Tasks.Task.Run(Sub() Thread.Sleep(1000))
        mbApiInterface.Player_PlayNextTrack()
    End Sub
Last Edit: February 28, 2017, 03:42:31 PM by stax76

boroda

  • Hero Member
  • *****
  • Posts: 4078
you could try to stop player before playing next track (without tasks and sleeping).

stax76

  • Jr. Member
  • **
  • Posts: 28
Quote
you could try to stop player before playing next track (without tasks and sleeping).

I tried it but it also don't work properly.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 33721
the NotificationType.TagsChanging and NotificationType.RatingChanging events only are messaged synchronously from the MB GUI thread.
If you do anything in the plugin that causes the API to invoke to the GUI thread then the plugin will block