Share via


Proprietà IWMPMedia::d uration

[La funzionalità associata a questa pagina, Lettore multimediale Windows SDK è una funzionalità legacy. È stato sostituito da MediaPlayer. MediaPlayer è stato ottimizzato per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi MediaPlayer invece di Lettore multimediale Windows SDK, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.

La proprietà duration ottiene la durata in secondi dell'elemento multimediale corrente.

Questa proprietà è di sola lettura.

Sintassi

public System.Double duration {get;}

Public ReadOnly Property duration As System.Double

Valore proprietà

Valore System.Double che rappresenta la durata in secondi.

Osservazioni:

Se questa proprietà viene utilizzata con un elemento multimediale diverso da quello specificato in AxWindowsMediaPlayer.currentMedia, potrebbe non contenere un valore valido.

Per recuperare la durata dei file che non si trovano nella libreria dell'utente, è necessario attendere che Lettore multimediale Windows aprire il file, ovvero l'oggetto OpenState corrente deve essere uguale a MediaOpen. Puoi verificarlo gestendo l'evento AxWindowsMediaPlayer._WMPOCXEvents_OpenStateChange o controllando periodicamente il valore di AxWindowsMediaPlayer.openState.

Per le playlist, la durata di ogni elemento multimediale può essere recuperata quando viene aperto il singolo elemento multimediale, anziché quando viene aperta la playlist.

Prima di usare questa proprietà, è necessario disporre dell'accesso in lettura alla libreria. Per altre informazioni, vedere Accesso alla libreria.

Esempi

Nell'esempio seguente viene utilizzata la durata per visualizzare il tempo rimanente nell'elemento multimediale corrente in un'etichetta. Un timer aggiorna il testo nell'etichetta ogni secondo.

// Set the timer to fire an event every second and start the timer.
timer.Interval = 1000;
timer.Start();

// Note:  Use the AxWindowsMediaPlayer.PlayStateChange event with a switch statement to
// determine when to start and stop the timer. 

private void TimerEventProcessor(object sender, System.EventArgs e)
{
    // Subtract the current position from the duration of the current media to get
    // the time remaining. Use the Math.floor method to round the result down to the
    // nearest whole number.
    double t = Math.Floor(player.currentMedia.duration - player.Ctlcontrols.currentPosition);

    // Display the time remaining in the current media.
    timeRemaining.Text = ("Seconds remaining: " + t.ToString());        
}

' Set the timer to fire an event every second and start the timer.
Timer.Interval = 1000
Timer.Start()

' Note:  Use the AxWindowsMediaPlayer.PlayStateChange event with a Select Case statement to
' determine when to start and stop the timer. 

Public Sub TimerEventProcessor(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick

    ' Subtract the current position from the duration of the current media to get
    ' the time remaining. Use the Math.Floor method to round the result down to the
    ' nearest whole number.
    Dim t As Double = Math.Floor(player.currentMedia.duration - player.Ctlcontrols.currentPosition)

    ' Display the time remaining in the current media.
    timeRemaining.Text = ("Seconds remaining: " + t.ToString())

End Sub

Requisiti

Requisito valore
Versione
Lettore multimediale Windows serie 9 o versioni successive
Spazio dei nomi
WMPLib
Assemblaggio
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

Vedi anche

AxWindowsMediaPlayer.currentMedia (VB e C#)

AxWindowsMediaPlayer.openState (VB e C#)

Evento AxWindowsMediaPlayer.OpenStateChange (VB e C#)

Interfaccia IWMPMedia (VB e C#)

IWMPMedia.durationString (VB e C#)