IWMPMedia ::d propriété figuration
La propriété Duration obtient la durée en secondes de l’élément multimédia actuel.
Cette propriété est en lecture seule.
Syntaxe
public System.Double duration {get;}
Public ReadOnly Property duration As System.Double
Valeur de la propriété
System. double qui correspond à la durée en secondes.
Notes
Si cette propriété est utilisée avec un élément multimédia autre que celui spécifié dans AxWindowsMediaPlayer. currentMedia, elle ne peut pas contenir de valeur valide.
pour récupérer la durée des fichiers qui ne sont pas dans la bibliothèque de l’utilisateur, vous devez attendre que Lecteur Windows Media ouvre le fichier ; autrement dit, le OpenState actuel doit être égal à MediaOpen. Vous pouvez le vérifier en gérant AxWindowsMediaPlayer. _ Événement WMPOCXEvents _ OpenStateChange ou en vérifiant régulièrement la valeur de AxWindowsMediaPlayer. openState.
Pour les sélections, la durée de chaque élément multimédia peut être récupérée lors de l’ouverture de l’élément multimédia individuel, plutôt que lors de l’ouverture de la sélection.
Avant d’utiliser cette propriété, vous devez disposer d’un accès en lecture à la bibliothèque. Pour plus d’informations, consultez accès à la bibliothèque.
Exemples
L’exemple suivant utilise Duration pour afficher l’heure restante dans l’élément multimédia actuel dans une étiquette. Un minuteur met à jour le texte de l’étiquette chaque seconde.
// 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
Spécifications
| Condition requise | Valeur |
|---|---|
| Version |
Lecteur Windows Media série 9 ou version ultérieure |
| Espace de noms |
WMPLib |
| Assembly |
|