Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

wmp.dll MediaPlayer playback nesting problem

Posted on 2009-05-14
6
Medium Priority
?
638 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
The viewer will learn how to search for and apply Apple Loops, as well as create their own in Logic Pro X. Record a region in the tracks area: Select the region: Go to File > Export > Region to Loop Library: Select the appropriate search terms…
Viewers will learn the basics of making and using Impulse Kits in Ableton Live. Load new Impulse into an empty MIDI track: Fill the 8 empty sample slots with drum samples: Adjust parameters to tailor each sound as desired: Proceed to create be…

604 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