Solved

wmp.dll MediaPlayer playback nesting problem

Posted on 2009-05-14
6
619 Views
Last Modified: 2013-12-07
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
Comment
Question by:MarkBottomley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24402408
Are you sure following condition is resolved true?
        If Not IsNothing(CurrentMedium) Then
            Play()
        End If
0
 

Author Comment

by:MarkBottomley
ID: 24408908
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24409629
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:MarkBottomley
ID: 24417220
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24419275
hmmm. This highlights the need of reading the search results from google carefully before posting links!
0
 

Accepted Solution

by:
MarkBottomley earned 0 total points
ID: 24472545
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Viewers will learn how to turn a Live Set into a compressed Live Pack file, and how to install Live Packs. Make: File > Collect All And Save: File > Manage Files: Click Manage Project: Click Create Pack: Select save location: Install: Doub…
Viewers will get an overview of how to make and use Drum Racks in Ableton Live. Load new Drum Rack into empty MIDI track: Fill rack with audio samples: Re-arrange sample slots as necessary: Adjust parameters of each slot to tailor each sound a…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question