È possibile farlo utilizzando la PlayStateChanged event. puoi aggiungerlo al tuo MediaPlayer in questo modo.
WMPLib.WindowsMediaPlayer wplayer;
wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(wplayer_PlayStateChange);
wplayer.URL = "c:/Standup.mp3";
wplayer.controls.play();
si può quindi verificare la MediaEnded
PlayState nel EventHandler e ripristinare la CurrentPosition per l'inizio della canzone:
void wplayer_PlayStateChange(int NewState)
{
if (NewState == (int)WMPLib.WMPPlayState.wmppsMediaEnded)
{
wplayer.controls.currentPosition = 0;
}
}
Edit: mi aspettavo di essere in grado di fare una canzone ripetibile al punto ero stufo di esso, e il codice di cui sopra ha funzionato quando ho avuto i punti di interruzione impostati. Una volta rimossi, ho scoperto che c'erano altri PlayStation che impedivano la riproduzione del file. Sono stato in grado di bypassarlo utilizzando un timer one shot .. Ora ho am stanco della canzone che stavo usando. Potrebbe/probabilmente essere un modo migliore per farlo, ma funzionerà.
Codice Modificato
public partial class Form1 : Form
{
WMPLib.WindowsMediaPlayer wplayer;
Timer tmr = new Timer();
public Form1()
{
InitializeComponent();
tmr.Interval = 10;
tmr.Stop();
tmr.Tick += new EventHandler(tmr_Tick);
wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "c:/Standup.mp3";
wplayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(wplayer_PlayStateChange);
wplayer.controls.play();
}
void tmr_Tick(object sender, EventArgs e)
{
tmr.Stop();
wplayer.controls.play();
}
void wplayer_PlayStateChange(int NewState)
{
if (NewState == (int)WMPLib.WMPPlayState.wmppsMediaEnded)
{
tmr.Start();
}
}
}
fonte
2013-07-15 00:17:48
Ho davvero non capiscono che link..Pls possono dare u un esempio di codice. –
Non ho usato questa libreria, ma dalla mia comprensione, dovresti essere in grado di usare: wplayer.settings.setMode ("loop", true); o wplayer.settings.setMode ("autoRewind", true); –