Title: Multimedia
1Multimedia
- Rujchai Ung-arunyawee
- Department of Computer Engineering
- Khon Kaen University
2Multimedia
3The Image
4The SoundPlayer
- Appeared in .NET 2.0
- The easiest, most lightweight way to add audio to
an application - Only play audio WAV files
- Doesnt support playing more than one sound at
once - Doesnt provide the ability to control
5Case 1 The audio is present in the same
directory as the compiled application
Case 2 if you add the ding.wav audio file with
the resource name Ding
6The SoundPlayerAction
- New feature that WPF introduces to make it more
convenient to use the SoundPlayer class - Allows you to use it in response to any event
- Uses a single property, Source
- Cannot play the audio in an embedded resource
7(No Transcript)
8System Sounds
- Based on the MessageBeep Win32 API
- Provides access only to the following generic
system sounds - Asterisk
- Beep
- Exclamation
- Hand
- Question
- For example, to sound a beep in your code
9The MediaPlayer
- Not only play WAV audio, but also play MP3 audio
or MPEG video
- Note
- The MediaPlayer is created outside the event
handler - You supply the location of your file as a URI.
- Theres no exception handling code
10(No Transcript)
11Using these members, you could build a basic but
full-featured media player. However, WPF
programmers usually use another quite similar
element, which is defined in the next section
the MediaElement class.
12The MediaElement
- Wraps all the functionality of the MediaPlayer
class. - Used as audio or video player
- Placed a tag directly in your user interface
- Declaratively supported.
13Simple Audio Player
- Adding this markup to your user interface, the
test.mp3 audio will be played as soon as its
loaded (which is more or less as soon as the
window is loaded).
14Playing Audio Programmatically
- To play audio programmatically, you must begin by
changing the LoadedBehavior - Interact with the media element in code
- Generally, interaction consists of the
straightforward Play(), Pause(), and Stop()
methods
15Handling Errors
16Control media declaratively
- By using the Trigger, Storyboard and
MediaTimeline - The following markup demonstrates a simple
example. It uses the BeginStoryboard action to
begin playing a sound when the mouse clicks a
button
17(No Transcript)
18Controlling playback
19(No Transcript)
20Playing Multiple Sounds
21(No Transcript)
22Synchronizing an Animation with Audio
- Simpler way is to segment the audio into
separate files - The other way is to use key frame animation by
wrapping this key frame animation and your
MediaTimeline into a single storyboard - When using key frame animation, its important to
set the Storyboard.SlipBehavior property to Slip - See text for example.
23Playing Video
- MediaElement class supports all the video formats
that are supported by Windows Media Player - Most important, the Stretch and StretchDirection
properties determine how the video window is
scaled to fit its container
24Video Effects
- You can use a MediaElement as the content inside
a content control, such as a button. - You can also combine video with transformations
through the LayoutTransform or RenderTransform
property. This allows you to move your video
window, stretch it, skew it, or rotate it. - You can set the Clipping property of the
MediaElement to cut down the video window to a
specific shape or path - You can set the Opacity property to allow other
content to show through behind your video window
25Video Effects (Cont.)
- You can use an animation to change a property of
the MediaElement (or one of its transforms)
dynamically. - You can copy the current content of the video
window to another place in your user interface
using a VisualBrush, which allows you to create
specific effects like reflection. - You can place a video window on a 3-D surface and
use an animation to move it as the video is being
played
26See text for the code
27Speech Synthesis
- A feature that generates spoken audio based on
text you supply - Speech synthesis isnt built into WPFinstead,
its a Windows accessibility feature. - Narrator use speech synthesis to help blind users
to navigate basic dialog boxes - More generally, speech synthesis can be used to
create audio tutorials and spoken instructions - All you need to do is create an instance of the
SpeechSynthesizer class from the
System.Speech.Synthesis namespace and call its
Speak() method with a string of text
28Use PromptBuilder for more controlable
29Speech Recognition
- A feature that translates user-spoken audio into
text - As with speech synthesis, speech recognition is a
feature of the Windows operating system. - Allows users with disabilities to interact with
common controls by voice - Allows hands-free computer use, which is useful
in certain environments.
30To use speech recognition
- The most straightforward way to use speech
recognition is - Create an instance of the SpeechRecognizer class
from the System.Speech.Recognition namespace - Then attach an event handler to the
SpeechRecognized event, which is fired whenever
spoken words are successfully converted to text - Retrieve the text in the event handler from the
SpeechRecognizedEvent-Args.Result property
31(No Transcript)
32(No Transcript)