@@ -71,44 +71,44 @@ interface for media playback.
7171
7272| Event | Description |
7373| -----------------| --------------------------------------------------------------|
74- | OnErrorOccurred | Occurs when an error is encountered during media operations. |
74+ | ErrorOccurred | Occurs when an error is encountered during media operations. |
7575
7676## Usage Examples
7777
7878### Basic Usage
7979
8080``` xaml
81- <MediaPlayerControl Name =" mediaPlayer " Source =" {Binding MediaSource}"
82- Volume =" 0.8"
83- LoadedBehavior =" AutoPlay" />
81+ <MediaPlayerControl Name =" mediaPlayerControl " Source =" {Binding MediaSource}"
82+ Volume =" 0.8"
83+ LoadedBehavior =" AutoPlay" />
8484```
8585
8686### Binding to Commands
8787
8888``` xaml
89- <Button Command =" {Binding #mediaPlayer .PlayPauseCommand}"
89+ <Button Command =" {Binding #mediaPlayerControl .PlayPauseCommand}"
9090 Content =" Play/Pause" />
9191
92- <Button Command =" {Binding #mediaPlayer .StopCommand}"
92+ <Button Command =" {Binding #mediaPlayerControl .StopCommand}"
9393 Content =" Stop" />
9494```
9595
9696### Error Handling
9797
9898``` csharp
99- mediaPlayer . OnErrorOccurred += (sender , args ) =>
99+ mediaPlayerControl . ErrorOccurred += (sender , args ) =>
100100{
101101 Console .WriteLine ($" Media error: {args .Message }" );
102102 args .Handled = true ; // Prevents the exception from being thrown.
103103 };
104104```
105105
106- ** Note** : This callback gives you the opportunity to reset the state of the ` MediaPlayer ` gracefully.
106+ ** Note** : This callback gives you the opportunity to reset the state of the ` MediaPlayerControl ` gracefully.
107+
107108
108109## Template Parts and Customization
109110
110- The default control template for ` MediaPlayerControl ` in ` Avalonia.Media.Themes.Fluent `
111- includes several key parts:
111+ The default control template for ` MediaPlayerControl ` includes several key parts:
112112
113113- ** PART_MediaPlayerPresenter** : Displays the video content
114114- ** MediaControlOverlay** : Contains the playback controls
@@ -117,49 +117,50 @@ includes several key parts:
117117The most basic configuration of the ` MediaPlayerControl ` can be like this:
118118
119119``` xml
120- <!-- Put this in a ResourceDictionary referenced by your app.
121- This by default replaces the -->
120+ <!-- In a ResourceDictionary referenced by your app. -->
122121<ControlTheme x : Key =" {x:Type MediaPlayerControl}" TargetType =" MediaPlayerControl" >
122+ <Setter Property =" Template" >
123123 <ControlTemplate >
124- <!-- This border is for decoration and for setting a default background for the control
125- When there's no media. -->
126- <Border Background =" Gray" ClipToBounds =" True" CornerRadius =" 4" >
127- <Panel >
128- <!-- This is used to have a dark background against the MediaPlayerPresenter when there's a
129- video to be displayed. -->
130- <Border IsVisible =" {TemplateBinding HasVideo}" >
131- <Border Background =" Black" IsVisible =" {TemplateBinding IsMediaActive}" />
132- </Border >
133-
134- <!-- This ViewBox is responsible on how the MediaPlayerPresenter is stretched to fit
135- the bounding area of the control. -->
136- <Viewbox >
137- <!-- The control in which the internal MediaPlayer draws the video -->
138- <MediaPlayerPresenter Name =" PART_MediaPlayerPresenter" />
139- </Viewbox >
140-
141- <!-- Example of the overlay playback controls.
142- Use the built-in Commands to easily control the playback. -->
143- <DockPanel LastChildFill =" True" MaxHeight =" 64" VerticalAlignment =" Bottom" >
144- <ProgressBar DockPanel.Dock=" Bottom"
145- IsIndeterminate =" True"
146- IsVisible =" {TemplateBinding IsBuffering}" />
147- <StackPanel Orientation =" Horizontal"
148- HorizontalAlignment =" Center"
149- Spacing =" 10"
150- Margin =" 5"
151- TextElement.FontSize=" 24" >
152- <Button Content =" ⏯ "
153- Padding =" 5,-5,5,0"
154- Command =" {TemplateBinding PlayPauseCommand}" />
155- <Button Content =" ⏹ "
156- Padding =" 5,-5,5,0"
157- Command =" {TemplateBinding StopCommand}" />
158- </StackPanel >
159- </DockPanel >
160- </Panel >
161- </Border >
124+ <!-- This border is for decoration and for setting a default background for the control
125+ When there's no media. -->
126+ <Border Background =" Gray" ClipToBounds =" True" CornerRadius =" 4" >
127+ <Panel >
128+ <!-- This is used to have a dark background against the MediaPlayerPresenter when there's a
129+ video to be displayed. -->
130+ <Border IsVisible =" {TemplateBinding HasVideo}" >
131+ <Border Background =" Black" IsVisible =" {TemplateBinding IsMediaActive}" />
132+ </Border >
133+
134+ <!-- This ViewBox is responsible on how the MediaPlayerPresenter is stretched to fit
135+ the bounding area of the control. -->
136+ <Viewbox >
137+ <!-- The control in which the internal MediaPlayer draws the video -->
138+ <MediaPlayerPresenter Name =" PART_MediaPlayerPresenter" />
139+ </Viewbox >
140+
141+ <!-- Example of the overlay playback controls.
142+ Use the built-in Commands to easily control the playback. -->
143+ <DockPanel LastChildFill =" True" MaxHeight =" 64" VerticalAlignment =" Bottom" >
144+ <ProgressBar DockPanel.Dock=" Bottom"
145+ IsIndeterminate =" True"
146+ IsVisible =" {TemplateBinding IsBuffering}" />
147+ <StackPanel Orientation =" Horizontal"
148+ HorizontalAlignment =" Center"
149+ Spacing =" 10"
150+ Margin =" 5"
151+ TextElement.FontSize=" 24" >
152+ <Button Content =" ⏯ "
153+ Padding =" 5,-5,5,0"
154+ Command =" {TemplateBinding PlayPauseCommand}" />
155+ <Button Content =" ⏹ "
156+ Padding =" 5,-5,5,0"
157+ Command =" {TemplateBinding StopCommand}" />
158+ </StackPanel >
159+ </DockPanel >
160+ </Panel >
161+ </Border >
162162 </ControlTemplate >
163+ </Setter >
163164</ControlTheme >
164165```
165166
@@ -195,7 +196,7 @@ flowchart LR
195196 class Init,Setup,Cleanup phase
196197```
197198
198- Here's a more comprehensive graph of ` MediaPlayerControl ` 's interactions with ` MediaPlayer ` over the course of its
199+ Here's a more comprehensive graph of ` MediaPlayerControl ` 's interactions with its internal ` MediaPlayer ` over the course of its
199200lifetime:
200201
201202``` mermaid
@@ -247,11 +248,11 @@ flowchart LR
247248## Best Practices
248249
2492501 . ** Error Handling** :
250- - Always subscribe to the ` OnErrorOccurred ` event to handle errors gracefully.
251- - Set the ` Handled ` property to true on the ` OnErrorOccurred ` event handler if you've managed the error.
251+ - Always subscribe to the ` ErrorOccurred ` event to handle errors gracefully.
252+ - Set the ` Handled ` property to true on the ` ErrorOccurred ` event handler if you've managed the error.
252253
2532542 . ** Resource Management** :
254- - The control manages the ` MediaPlayer ` lifecycle automatically.
255+ - The control manages the ` MediaPlayerControl ` lifecycle automatically.
255256
2562573 . ** UI Integration** :
257258 - Use the built-in commands for integrating with custom buttons/controls.
@@ -260,4 +261,4 @@ flowchart LR
260261## Related Components
261262
262263- [ MediaPlayer] ( mediaplayer.md )
263- - [ MediaSource] ( mediasource.md )
264+ - [ MediaSource] ( mediasource.md )
0 commit comments