integrating-wpf-media
Integrates multimedia content in WPF including MediaElement video/audio playback, Image control display, and SoundPlayerAction effects. Use when building media players, galleries, or multimedia UIs.
What this skill does
# WPF Media Integration Patterns
Integrating multimedia content such as images, video, and audio in WPF.
## 1. Image Control
### 1.1 Basic Image Display
```xml
<!-- Resource image -->
<Image Source="/Assets/logo.png" Width="100" Height="100"/>
<!-- Absolute path -->
<Image Source="C:\Images\photo.jpg"/>
<!-- URI -->
<Image Source="https://example.com/image.png"/>
<!-- Pack URI (embedded resource) -->
<Image Source="pack://application:,,,/MyAssembly;component/Images/icon.png"/>
```
### 1.2 Stretch Options
```xml
<!-- None: maintain original size -->
<Image Source="/photo.jpg" Stretch="None"/>
<!-- Fill: stretch to fit area (ignore aspect ratio) -->
<Image Source="/photo.jpg" Stretch="Fill"/>
<!-- Uniform: maintain aspect ratio, maximum size within area -->
<Image Source="/photo.jpg" Stretch="Uniform"/>
<!-- UniformToFill: maintain aspect ratio, fill area (may crop) -->
<Image Source="/photo.jpg" Stretch="UniformToFill"/>
```
### 1.3 Dynamic Image Loading
```csharp
namespace MyApp.Helpers;
using System;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;
public static class ImageHelper
{
/// <summary>
/// Load image from file
/// </summary>
public static BitmapImage LoadFromFile(string filePath)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(filePath, UriKind.Absolute);
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze(); // Can be used outside UI thread
return bitmap;
}
/// <summary>
/// Load image from stream
/// </summary>
public static BitmapImage LoadFromStream(Stream stream)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
/// <summary>
/// Load thumbnail (memory optimization)
/// </summary>
public static BitmapImage LoadThumbnail(string filePath, int maxWidth, int maxHeight)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(filePath, UriKind.Absolute);
bitmap.DecodePixelWidth = maxWidth;
bitmap.DecodePixelHeight = maxHeight;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
return bitmap;
}
/// <summary>
/// Load image from Base64
/// </summary>
public static BitmapImage LoadFromBase64(string base64)
{
var bytes = Convert.FromBase64String(base64);
using var stream = new MemoryStream(bytes);
return LoadFromStream(stream);
}
}
```
### 1.4 Image Load Events
```csharp
// XAML
// <Image x:Name="DynamicImage" ImageFailed="OnImageFailed"/>
private void LoadImageAsync(string url)
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(url);
bitmap.EndInit();
// Loading complete event
bitmap.DownloadCompleted += (s, e) =>
{
// Image load complete
};
// Loading failed event
bitmap.DownloadFailed += (s, e) =>
{
// Error handling
};
// Loading progress
bitmap.DownloadProgress += (s, e) =>
{
var progress = e.Progress; // 0-100
};
DynamicImage.Source = bitmap;
}
```
---
## 2. MediaElement (Video/Audio)
### 2.1 Basic Usage
```xml
<!-- Auto-play video -->
<MediaElement Source="/Videos/intro.mp4"
LoadedBehavior="Play"
UnloadedBehavior="Stop"/>
<!-- Manual control video -->
<MediaElement x:Name="VideoPlayer"
Source="/Videos/movie.mp4"
LoadedBehavior="Manual"
UnloadedBehavior="Stop"
MediaOpened="OnMediaOpened"
MediaEnded="OnMediaEnded"
MediaFailed="OnMediaFailed"/>
```
### 2.2 LoadedBehavior Options
| Value | Description |
|-------|-------------|
| **Play** | Auto-play |
| **Pause** | Pause after load |
| **Stop** | Stop after load |
| **Manual** | Control via code |
| **Close** | Close media |
### 2.3 Video Player Implementation
```csharp
namespace MyApp.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
public sealed partial class VideoPlayerControl : UserControl
{
private readonly DispatcherTimer _positionTimer;
private bool _isDragging;
public VideoPlayerControl()
{
InitializeComponent();
_positionTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(200)
};
_positionTimer.Tick += OnPositionTimerTick;
}
private void OnMediaOpened(object sender, RoutedEventArgs e)
{
// Display total duration
if (VideoPlayer.NaturalDuration.HasTimeSpan)
{
var duration = VideoPlayer.NaturalDuration.TimeSpan;
PositionSlider.Maximum = duration.TotalSeconds;
TotalTimeText.Text = FormatTime(duration);
}
_positionTimer.Start();
}
private void OnMediaEnded(object sender, RoutedEventArgs e)
{
_positionTimer.Stop();
VideoPlayer.Stop();
VideoPlayer.Position = TimeSpan.Zero;
}
private void OnMediaFailed(object sender, ExceptionRoutedEventArgs e)
{
// Media load failed
MessageBox.Show($"Media load failed: {e.ErrorException.Message}");
}
private void OnPositionTimerTick(object? sender, EventArgs e)
{
if (!_isDragging)
{
PositionSlider.Value = VideoPlayer.Position.TotalSeconds;
CurrentTimeText.Text = FormatTime(VideoPlayer.Position);
}
}
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
VideoPlayer.Play();
_positionTimer.Start();
}
private void PauseButton_Click(object sender, RoutedEventArgs e)
{
VideoPlayer.Pause();
}
private void StopButton_Click(object sender, RoutedEventArgs e)
{
VideoPlayer.Stop();
_positionTimer.Stop();
}
private void PositionSlider_DragStarted(object sender, EventArgs e)
{
_isDragging = true;
}
private void PositionSlider_DragCompleted(object sender, EventArgs e)
{
_isDragging = false;
VideoPlayer.Position = TimeSpan.FromSeconds(PositionSlider.Value);
}
private void VolumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
VideoPlayer.Volume = e.NewValue;
}
private static string FormatTime(TimeSpan time)
{
return time.Hours > 0
? $"{time:hh\\:mm\\:ss}"
: $"{time:mm\\:ss}";
}
}
```
### 2.4 VideoPlayerControl XAML
```xml
<UserControl x:Class="MyApp.Controls.VideoPlayerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Video area -->
<MediaElement x:Name="VideoPlayer"
LoadedBehavior="Manual"
UnloadedBehavior="Stop"
MediaOpened="OnMediaOpened"
MediaEnded="OnMediaEnded"
MediaFailed="OnMediaFailed"/>
<!-- Control bar -->
<Grid Grid.Row="1" Background="#CC000000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.