Solved

wmp.dll MediaPlayer playback nesting problem

Posted on 2009-05-14
6
593 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
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

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

Author Comment

by:MarkBottomley
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:MarkBottomley
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Viewers will learn the basics of creating custom device Racks in Ableton Live. Place instrument(s) and effects onto a track, and select them all by holding the Shift key and clicking on the device title bars: Group them by typing Command-G (Ctrl-G…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now