Événement PlayStateChange de l’objet AxWindowsMediaPlayer
[La fonctionnalité associée à cette page, Lecteur multimédia Windows SDK, est une fonctionnalité héritée. Il a été remplacé par MediaPlayer. MediaPlayer a été optimisé pour Windows 10 et Windows 11. Microsoft recommande vivement que le nouveau code utilise MediaPlayer au lieu de Lecteur multimédia Windows SDK, lorsque cela est possible. Microsoft suggère que le code existant qui utilise les API héritées soit réécrit pour utiliser les nouvelles API si possible.]
L’événement PlayStateChange se produit lorsque l’état de lecture du contrôle Lecteur multimédia Windows change.
[C#]
private void player_PlayStateChange(
object sender,
_WMPOCXEvents_PlayStateChangeEvent e
)
[Visual Basic]
Private Sub player_PlayStateChange(
sender As Object,
e As _WMPOCXEvents_PlayStateChangeEvent
) Handles player.PlayStateChange
Données d'événements
Le gestionnaire associé à cet événement est de type AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler. Ce gestionnaire reçoit un argument de type AxWMPLib._WMPOCXEvents_PlayStateChangeEvent, qui contient la propriété suivante liée à cet événement.
Propriété | Description |
---|---|
newState | System.Int32Specifie le nouvel état. |
Notes
Lecteur multimédia Windows états ne sont pas garantis dans un ordre particulier. En outre, tous les états ne se produisent pas nécessairement pendant une séquence d’événements. Vous ne devez pas écrire de code qui s’appuie sur l’ordre d’état.
Exemples
L’exemple suivant illustre un gestionnaire d’événements pour l’événement PlayStateChange qui affiche l’état de lecture actuel dans une étiquette. L’objet AxWMPLib.AxWindowsMediaPlayer est représenté par la variable nommée player.
// Add a delegate for the PlayStateChange event.
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
// Test the current state of the player and display a message for each state.
switch (e.newState)
{
case 0: // Undefined
currentStateLabel.Text = "Undefined";
break;
case 1: // Stopped
currentStateLabel.Text = "Stopped";
break;
case 2: // Paused
currentStateLabel.Text = "Paused";
break;
case 3: // Playing
currentStateLabel.Text = "Playing";
break;
case 4: // ScanForward
currentStateLabel.Text = "ScanForward";
break;
case 5: // ScanReverse
currentStateLabel.Text = "ScanReverse";
break;
case 6: // Buffering
currentStateLabel.Text = "Buffering";
break;
case 7: // Waiting
currentStateLabel.Text = "Waiting";
break;
case 8: // MediaEnded
currentStateLabel.Text = "MediaEnded";
break;
case 9: // Transitioning
currentStateLabel.Text = "Transitioning";
break;
case 10: // Ready
currentStateLabel.Text = "Ready";
break;
case 11: // Reconnecting
currentStateLabel.Text = "Reconnecting";
break;
case 12: // Last
currentStateLabel.Text = "Last";
break;
default:
currentStateLabel.Text = ("Unknown State: " + e.newState.ToString());
break;
}
}
Public Sub player_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles player.PlayStateChange
' Test the current state of the player, display a message for each state.
Select Case e.newState
Case 0 ' Undefined
currentStateLabel.Text = "Undefined"
Case 1 ' Stopped
currentStateLabel.Text = "Stopped"
Case 2 ' Paused
currentStateLabel.Text = "Paused"
Case 3 ' Playing
currentStateLabel.Text = "Playing"
Case 4 ' ScanForward
currentStateLabel.Text = "ScanForward"
Case 5 ' ScanReverse
currentStateLabel.Text = "ScanReverse"
Case 6 ' Buffering
currentStateLabel.Text = "Buffering"
Case 7 ' Waiting
currentStateLabel.Text = "Waiting"
Case 8 ' MediaEnded
currentStateLabel.Text = "MediaEnded"
Case 9 ' Transitioning
currentStateLabel.Text = "Transitioning"
Case 10 ' Ready
currentStateLabel.Text = "Ready"
Case 11 ' Reconnecting
currentStateLabel.Text = "Reconnecting"
Case 12 ' Last
currentStateLabel.Text = "Last"
Case Else
currentStateLabel.Text = ("Unknown State: " + e.newState.ToString())
End Select
End Sub
Configuration requise
Condition requise | Valeur |
---|---|
Version |
série Lecteur multimédia Windows 9 ou ultérieure |
Espace de noms |
AxWMPLib |
Assembly |
|
Voir aussi
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour