# MediaNode
Class Inherits Node
## About
`MediaNode` is the shared base for audio and video resources. It manages local-file and URL sources, portable source data, selection-dependent playback controls, static previews, resizing, and cleanup. Windows and Linux use an HTML5 player hosted by `DesktopHTMLViewer`; macOS uses `DesktopMoviePlayer`.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| ActionItem | index As Integer | ToolbarItem | Returns the contextual toolbar item at the specified index. |
| AddVectorPDFAnnotations | pdf As PDFDocument <br> pageNumber As Integer <br> offsetX As Double <br> offsetY As Double <br> usedNames As Dictionary <br> formAction As String = "" | (None) | Adds this node's interactive annotations and form controls to a vector PDF page. Override for custom nodes. |
| AttachEmbeddedControls | editor As Editor | (None) | Creates and attaches any native controls required while this node is active. |
| BackgroundToolbarItem | (None) | ToolbarItem | Returns the default node-background popover toolbar item. |
| ClearResource | (None) | (None) | Clears resource from this media node. |
| ConfigureEmbeddedPlayer | player As DesktopMoviePlayer | (None) | Configures the embedded movie player when it is created. |
| Constructor | (None) | (None) | Creates a new media node instance initialized from the supplied values. |
| Destructor | (None) | (None) | Releases resources owned by this media node instance. |
| DetachEmbeddedControls | (None) | (None) | Stops and removes native controls created by this node. |
| EmbeddedControlBounds | bounds As Rect | Rect | Returns the bounds of the embedded player within the supplied node bounds. |
| EmbeddedPlayerVisible | (None) | Boolean | Returns whether the embedded player is shown on this platform. |
| ExportStyles | stylesheet As GraffitiProEditor.Stylesheet | (None) | Adds the stylesheet rules this node type's HTML output uses. |
| FromHTML | element As GraffitiProEditor.HTMLSupport.HTMLElement | Boolean | Imports supported content and formatting from an HTML element and returns whether it succeeded. |
| FromJSON | data As JSONItem | Boolean | Restores state from JSON data and returns whether it succeeded. |
| InspectorSections | (None) | InspectorSection | Returns the user-editable media value properties exposed by the inspector. |
| LastActionIndex | (None) | Integer | Returns the last zero-based action index supplied by this node, or -1 when there are no actions. |
| MediaFileFilter | (None) | String | Returns the open-file dialog filter for choosing this node's media file. Subclasses return their formats; empty allows any file. |
| PerformAction | index As Integer <br> selectedItem As DesktopMenuItem | (None) | Handles the contextual toolbar action at the specified index. |
| Play | (None) | (None) | Starts embedded playback of this media node's resource. |
| ResourceAvailable | (None) | Boolean | Returns whether the node has a local file, URL, or embedded source to play. |
| ResourceSource | (None) | String | Returns the media source used for playback and export: the embedded data, the URL, or the file. |
| ResourceTitle | (None) | String | Returns the name shown for the media: the file's display name or the URL. |
| ScrollChanged | bounds As Rect | (None) | Updates native child controls for the node's current visible bounds. |
| SetResource | file As FolderItem | (None) | Assigns the node's local media file and clears its remote resource URL. |
| SetResource | url As String | (None) | Assigns the node's remote resource URL. |
| ToJSON | (None) | JSONItem | Returns a JSON representation of this object's persistent state. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| Attributes | LastPlaybackError | (None) | (None) |
| LocalFile | FolderItem | (None) | Gets or sets the local media file selected in the inspector. |
| ResourceFile | FolderItem | (None) | Gets or sets the local media file used by this node. |
| ResourceURL | String | (None) | Gets or sets the remote media URL used by this node. |
| URL | String | (None) | Gets or sets the remote media URL selected in the inspector. |
## Notes
Subclasses supply the media-specific static presentation and HTML element.
### JSON Format
`resourcePath` is the native path of a selected local file, `resourceURL` is a remote URL string, and `resourceData` is the portable encoded source when available. Restoration attempts an existing local path first, then portable data, then the URL. Common dimensions and alignment use the base `Node` JSON fields.
Consumers should treat `resourcePath` as a local optimization rather than a portable identifier. Preserve `resourceData` when documents must move between computers.
### Playback Lifecycle
Media nodes retain static canvas previews until selected. Embedded players are shown only when interaction is appropriate, are positioned from the node's scroll bounds without cycling visibility on every repaint, and stop playback when hidden or scrolled out of use. `DesktopHTMLViewer` streams remote Windows and Linux resources directly and can use server-supported range requests for seeking. Subclasses should use this lifecycle instead of opening resources externally.