Multimedia Coding
description
Transcript of Multimedia Coding
![Page 1: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/1.jpg)
Multimedia CodingMultimedia Coding
![Page 2: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/2.jpg)
Objectives of this Objectives of this topic:topic:
import movies, sound and flash video using AS3 code
You can …
control the playback of those items
![Page 3: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/3.jpg)
OverviewOverviewLoading External Images and
SWFsCommunicating with Loaded
MoviesLoading SoundStarting and Stopping SoundManaging the Volume of SoundLoading VideoControlling Video Playback
![Page 4: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/4.jpg)
Loading External Images and Loading External Images and SWFsSWFsLoad a variety of images and
external swf files into a Flash movie using AS3
The files are external which are not on the library panel
URLRequest class is used to get the location of the external image file
var imageRequest:URLRequest = new URLRequest("snowboard.jpg");
![Page 5: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/5.jpg)
Followed by loading instruction to create an image loader – Loader class
var imageLoader:Loader = new Loader();imageLoader.load(imageRequest);addChild(imageLoader);
load() is method instructing the Loader to load the imageRequest file, ‘snowboard.jpg’ (Loading_Images)
![Page 6: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/6.jpg)
Type of image files that can be loaded in Flash movie – jpeg, png, and gif files◦GIF files – best suited for graphics
and logos, rather than photographs or more complicated images, because of the limited color palette. It uses 256 colors in the 24-bit RGB
![Page 7: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/7.jpg)
◦PNG files – used mainly for less color intensive graphics. Do not support animation as GIFs, but support more transparency and produce smaller file sizes than GIFs
◦JPEG files – smaller file sizes for photograph image. The most popular choice for photographs that are destined for the Web.
![Page 8: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/8.jpg)
External SWF file load a SWF into another SWF file when intend to use the movie throughout the site.
SWF files are type of reusable asset that can be used in different project or replicated throughout a single project. (Loading_SWFMovie)
![Page 9: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/9.jpg)
Communicating with Loaded Communicating with Loaded MoviesMoviesModify objects in an external
SWF file that has been loaded into another Flash movie
The modification can be done when only the external SWF file is completed loading.
![Page 10: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/10.jpg)
The following is the code that will trigger the onComplete event when SWF file is finished loading
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
![Page 11: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/11.jpg)
contentLoaderInfo - property of the Loader class that contains all the information about the target file (the external file that is being loaded)
To communicate with the loaded SWF file, export the class definition for that object at run time.
![Page 12: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/12.jpg)
Write the AS3 code to activate the external SWF file.
Flash: Communicating, moviefunction
onComplete(event:Event):void{
event.target.content.boarder_mc.y -= 100;
}
![Page 13: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/13.jpg)
event.target the object being targeted by the event listener which is called contentLoaderInfo.
content property referring to the actual object in the external movie
boarder_mc instance name of the movie clip residing in the external movie
![Page 14: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/14.jpg)
Loading SoundsLoading SoundsUsing the same code,
URLRequest class to points to the sound file. (Sound)
var soundReq:URLRequest = new URLRequest("free_fade.mp3");
var sound:Sound = new Sound();sound.load(soundReq);
![Page 15: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/15.jpg)
Three types of sound files in Flash CS3, and another six more files if QuickTime 4 is installed on users PC
Capable to import 8-bit or 16-bit sounds
Without QuickTime QuickTime
WAV, AIFF, MP3 AIFF, SDII, MOV, AU, SND, WAV
![Page 16: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/16.jpg)
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void{
sound.play();}
Flash: Sound_Complete
![Page 17: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/17.jpg)
Control the SoundControl the SoundUse SoundChannel class to
control the sound playback
var soundControl:SoundChannel = new SoundChannel();
Create new instance of the SoundChannel class named soundControl (Starting_Stopping)
![Page 18: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/18.jpg)
addEventListener is used to add interactivity to the external movie through the button
play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
![Page 19: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/19.jpg)
Activate the playSound and stopSound event handler
function playSound(event:MouseEvent):void{
soundControl = sound.play();}function stopSound(event:MouseEvent):void{
soundControl.stop();}
![Page 20: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/20.jpg)
Pausing the sound◦Pause and resume the sound – the
sound starts to play from wherever the user stopped the track.
Flash: Pause_Resume
![Page 21: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/21.jpg)
Sound class in Flash
Class Description
Sound This loads sounds and starts a sound playing
SoundChannel Once a sound plays in Flash, a corresponding SoundChannel object is created for that sound. SoundChannel is used to control the playback
SoundMixer This control the playback of all sounds that are currently playing in a Flash movie
Microphone This captures audio input and controls the properties of the sound stream
SoundTransform
This control the volume of a sound. A SoundTransform object can be applied to Sound, SoundChannel, and Microphone object
![Page 22: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/22.jpg)
Managing the Volume of Managing the Volume of SoundSoundUse SoundTransform class to
deal the volume of a sound
var volumeControl:SoundTransform = new SoundTransform();
Create new instance of the SoundTransform class
![Page 23: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/23.jpg)
Volume in sound property has a possible value between 0 – 1.
volumeControl.volume += .5;soundControl.soundTransform =
volumeControl;
‘+= .1’ means increase the current volume by 50% every time the button is clicked (Volume_Control)
![Page 24: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/24.jpg)
1. Loading video with NetConnection object to stream a video from local drive or server var videoConnection:NetConnection = new NetConnection();
2. Specify the address source. ‘null’ same folder
videoConnection.connect(null);
Loading VideoLoading Video
![Page 25: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/25.jpg)
3. Use NetStream object to connects to the hard drive using NetConnection path and streams the video passsed through in the parentheses
var videoStream:NetStream = new NetStream(videoConnection);
videoStream.play("short_jump.flv");
![Page 26: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/26.jpg)
4. Attach the stream of the video and add it to the movie’s display list
var video:Video = new Video();video.attachNetStream(videoStream);addChild(video);
![Page 27: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/27.jpg)
var videoConnection:NetConnection = new NetConnection();videoConnection.connect(null);var videoStream:NetStream = new NetStream(videoConnection);videoStream.play("short_jump.flv");var video:Video = new Video();video.attachNetStream(videoStream);addChild(video);
Flash: Loading_Video
![Page 28: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/28.jpg)
Controlling Video PlaybackControlling Video PlaybackControl the playback of loaded
FLV files and handle the error messages during playback
Video playback do not use addEventListener method to listen for or process
It is applied the listener to the object that the client property of a NetStream instance references
![Page 29: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/29.jpg)
var metaListener:Object = new Object();metaListener.onMetaData = onMetaData;
metaListener is an instance of the Object class which accepts all the methods and properties of any object descended from it
Second statement associates the new onMetaData() method (or event listener) with the generic object metaListener
![Page 30: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/30.jpg)
videoStream.client = metaListener;
videoStream.client is one of the only objects that can be applied the event listener to in the external file.
By associating it with the generic object, than we can listen for onMedaData
Flash: Video_Playback
![Page 31: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/31.jpg)
function onMetaData(data:Object):void
{
play_btn.addEventListener(MouseEvent.CLICK,
playMovie);
stop_btn.addEventListener(MouseEvent.CLICK,
stopMovie);
}
Put the event listener in the function to make sure the external data (video) is fully loaded (Video_Control)
![Page 32: Multimedia Coding](https://reader035.fdocuments.us/reader035/viewer/2022062723/56813e33550346895da819d0/html5/thumbnails/32.jpg)
function playMovie(event:MouseEvent):void
{
videoStream.play("short_jump.flv");
}
function stopMovie(event:MouseEvent):void
{
videoStream.pause();
}