Solved

wmp.dll MediaPlayer playback nesting problem

Posted on 2009-05-14
6
605 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Populating an array of locale_time_info 8 46
vb.net 2 43
VB 2005 how to get a new line of data each time I try to write to a file. 10 24
Help with exporting to excel 4 26
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
This video will demonstrate how to customize windows, tools, and control bars, and save them as screen sets. Open and resize windows: Customize the toolbar: Customize the control bar: Customize your tool selections: Your screen set is alread…
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…

786 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