How to get TWindowsMediaPlayer to play a new track after completing the old?

I am using TWindowsMediaPlayer and am facing a problem. After the current song ends, I cannot download it to download a new song and then play it.

procedure TMainWinForm.WMPlayer1PlayStateChange(Sender: TObject; NewState: Integer); begin if (NewState = wmppsMediaEnded) then begin WMPlayer1.URL := FileScanner.SelectSong; writeln('Play triggered on ', String(WMPlayer1.URL)); WMPlayer1.controls.Play; // DOES NOT PLAY THE SONG! end; end; 

This downloads the song, but additional user intervention is required to play it. The only way I can continue is to check for wmppsStopped, but this event happens twice, so I get every odd numbered song in the list.

Any ideas on how to make it work correctly?

+4
source share
2 answers

I got an answer that seems to work. Since TWindowsMediaPlayer seems to work asynchronously, you cannot fire events using methods without letting others. To this end, I assume that he rejected the playback method because the media was not loaded properly.

 procedure TMainWinForm.WMPlayer1OpenStateChange(Sender: TObject; NewState: Integer); begin if NewState = wmposMediaOpen then begin WMPlayer1.controls.play; end; end; procedure TMainWinForm.WMPlayer1PlayStateChange(Sender: TObject; NewState: Integer); begin if (NewState = wmppsStopped) and (SpecialPlayListMode) then begin WMPlayer1.URL := FileScanner.SelectSong; end; end; 

Although this does not explain why I can change the URL, while something else is playing and losing without any problems ...

0
source

Why don't you use WMPlayer1.Mediacollection ?

Otherwise, you checked with WMPlayer1.settings.autoStart := True; before giving a new URL?

0
source

Source: https://habr.com/ru/post/1481277/


All Articles