• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

wmp.dll MediaPlayer playback nesting problem

I have been trying to use the MediaPlayer in a "nested" mode.  e.g. While I am playing a clip, I will pause it, record the currentPosition of the clip, and play a new clip to completion and then restart the previous clip.  Nesting levels can go deeper, but once the single level problem is solved, the nesting is free.  The problem I have is that when I restore the previous audio clip's state in response to a MediaEnded PlayStateChange, the restored clip does not start inspite of the call to the mediaplayer's play() method.  Below is the core of the code I have and i uses an existing mediaplayer on my form.

The mediaplayer data seems correct, but it is in the ready state (10), not playing when it "hangs"

http://msdn.microsoft.com/en-us/library/dd564085(VS.85).aspx is the playstate list I am using and it appears correct when I watched debug prints
Public Class Medium
 
    ' unrelated stuff stripped
    Private mFile As String = ""
    Private mCurrentPosition As Double = 0
    Private mPreviousMedium As Medium
 
    Public Property PreviousMedium() As Medium
        Get
            Return mPreviousMedium
        End Get
        Set(ByVal value As Medium)
            mPreviousMedium = value
        End Set
    End Property
 
    Public Property File() As String
        Get
            Return mFile
        End Get
        Set(ByVal value As String)
            mFile = value
        End Set
    End Property
 
    Public Property CurrentPosition() As Double
        Get
            Return mCurrentPosition
        End Get
        Set(ByVal value As Double)
            mCurrentPosition = value
        End Set
    End Property
 
End Class
 
 
Module MediaSequencer
    Dim CurrentMedium As Medium = Nothing
 
    Public Sub Add(ByVal NewMedium As Medium)
        ' Stack new Media entry and cause to play
        ' if already playing then reset to the start
        ' pause the currently playing media
        Pause()
        If NewMedium.Equals(CurrentMedium) Then
            CurrentMedium.CurrentPosition = 0D
        Else
            NewMedium.PreviousMedium = CurrentMedium
            CurrentMedium = NewMedium
        End If
        Play()
    End Sub
 
    Public Sub Remove()
        ' called when MediaEnded occurs
        ' get the previous playing clip
        Dim temp As Medium
        temp = CurrentMedium.PreviousMedium
        CurrentMedium.PreviousMedium = Nothing
        CurrentMedium = temp
        If Not IsNothing(CurrentMedium) Then
            Play()
        End If
    End Sub
 
    Public Sub Play()
        Player.URL = CurrentMedium.File
        Player.Ctlcontrols.currentPosition = CurrentMedium.CurrentPosition
        Player.Ctlcontrols.play()
    End Sub
 
    Public Sub Pause()
        If Not IsNothing(CurrentMedium) Then
            If Player.playState = WMPLib.WMPPlayState.wmppsPlaying Then
                Player.Ctlcontrols.pause()
                CurrentMedium.CurrentPosition = Player.Ctlcontrols.currentPosition
                ' this seems as though it shouldn't be here
                Player.Ctlcontrols.stop()
            End If
        End If
    End Sub
 
    Public Sub Abort()
        .Player.Ctlcontrols.stop()
        CurrentMedium = Nothing
    End Sub
 
End Module
 
 
' and the event handler
 
    Private Sub Player_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles Player.PlayStateChange
        If e.newState = WMPLib.WMPPlayState.wmppsMediaEnded Then
            MediaSequencer.Remove()
        End If
    End Sub

Open in new window

0
MarkBottomley
Asked:
MarkBottomley
  • 3
  • 3
1 Solution
 
CodeCruiserCommented:
Are you sure following condition is resolved true?
        If Not IsNothing(CurrentMedium) Then
            Play()
        End If
0
 
MarkBottomleyAuthor Commented:
Debug.Print outputs show that I do pass through that code path as expected.  Further outputs show that the player is in Mode 10 - Ready mode at that point.  If I hit my pause and play buttons, then it will continue to play the  original (outer nested) media clip from the interruption point.  I am assuming there is some sequence to "reset" the state of the player prior to getting it to resume playing and I am missing that magic sequence.  I have tried many variations including several  attempts at state sequence logic inside the PlayStateChanged method with no success and often looping of infinite nesting in the PlayStateChanged handler.  It should be working as I expect according to the portions of documentation I have seen.

Version is: 11.0.5721.5260 as output from the VersionInfo
0
 
CodeCruiserCommented:
Why do you use
Player.Ctlcontrols.play()

and not
Player.Play()?


http://msdn.microsoft.com/en-us/library/ms909968.
http://msdn.microsoft.com/en-us/library/ms909930.aspx
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MarkBottomleyAuthor Commented:
The link you are sending is the WinCE Player - a different control completely.  The control I'm using from the wmp.dll does not support Play/Pause/... controlling methods directly, but through the Ctlcontrols layer. (I have also found many different documentation sources because there are several MediaPlayer/WindowsMediaPlayer controls with no overview or documentation to separate them.  I have tried the other version, but it is much more restricted on the functionality and supported media encodings. - Question still stands - what am I not doing correct with the command sequence
0
 
CodeCruiserCommented:
hmmm. This highlights the need of reading the search results from google carefully before posting links!
0
 
MarkBottomleyAuthor Commented:
The only effective solution I have come up with is to use a timer that checks to see what I want to happen e.g. Play, and then checks the MediaPlayer state and if it is not in the Play state, then it re-issues the Play command.  Crude, very much a hack, but it achieves my goal.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now