Media Playback Controls Delphi integration for Windows 8/8.1/10/11
This library is part of the Codrut's Windows Runtime for Delphi, all units can be found there.
Attention! The app must be registered with a TAppRegistration, for futher detalies, look at the Cod Windows Runtime docs.
PlayControls := TWindowMediaTransportControls.Create;
PlayControls.MediaPlaybackType := TMediaPlaybackType.Music;
PlayControls.SupportedMediaControls := [TMediaControlAction.Play,
TMediaControlAction.Pause, TMediaControlAction.Stop,
TMediaControlAction.SkipPrevious, TMediaControlAction.SkipNext];
// Set info (in this case music, but for other types use the respective class)
PlayControls.InfoMusic.Title := 'Song name';
PlayControls.InfoMusic.AlbumArtist := 'Artist123';
// PlayControls.Thumbnail := ImageGraphic; // a PNG, JPEG, GIF or valid image type supported by windows
PlayControls.UpdateInformation;
// Enable
PlayControls.EnablePlayer := true;
// Status
PlayControls.PlaybackStatus := TMediaPlaybackStatus.Playing;
For windows, this information is mostly unused as It's not displayed in the Action Center. It's reccomended to not update this too often. Once every few seconds should be enough
// Timeline
PlayControls.Timeline.StartTime := 0;
PlayControls.Timeline.EndTime := 90*1000;
PlayControls.Timeline.Position := 5000;
PlayControls.PushTimeline;
With the help of TSubscriptionEventHandler class, you can register multiple events at the same time.
interface
type
TMyCustomClass = class(TObject)
public
procedure RequestPos(Sender: TTransportCompatibleClass; P: int64);
procedure RequestRate(Sender: TTransportCompatibleClass; R: double);
procedure RequestShuffle(Sender: TTransportCompatibleClass; S: boolean);
procedure RequestRepeat(Sender: TTransportCompatibleClass; R: TMediaPlaybackAutoRepeatMode);
end;
implementation
initialization
// Events
PlayControls.OnButtonPressed.Add( ButtonPressed );
PlayControls.OnPlaybackPositionChangeRequested.Add( RequestPos );
PlayControls.OnPlaybackRateChangeRequested.Add( RequestRate );
PlayControls.OnShuffleEnabledChangeRequested.Add( RequestShuffle );
PlayControls.OnRepeatModeChangeRequested.Add( RequestRepeat );