+ All Categories
Home > Documents > Multimedia Coding

Multimedia Coding

Date post: 07-Jan-2016
Category:
Upload: baird
View: 27 times
Download: 0 times
Share this document with a friend
Description:
Multimedia Coding. Objectives of this topic:. You can …. import movies, sound and flash video using AS3 code. control the playback of those items. Overview. Loading External Images and SWFs Communicating with Loaded Movies Loading Sound Starting and Stopping Sound - PowerPoint PPT Presentation
32
Multimedia Coding
Transcript
Page 1: Multimedia Coding

Multimedia CodingMultimedia Coding

Page 2: Multimedia Coding

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

OverviewOverviewLoading External Images and

SWFsCommunicating with Loaded

MoviesLoading SoundStarting and Stopping SoundManaging the Volume of SoundLoading VideoControlling Video Playback

Page 4: Multimedia Coding

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

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

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

◦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

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

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

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

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

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

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

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

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

sound.addEventListener(Event.COMPLETE, onComplete);

function onComplete(event:Event):void{

sound.play();}

Flash: Sound_Complete

Page 17: Multimedia Coding

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

function playMovie(event:MouseEvent):void

{

videoStream.play("short_jump.flv");

}

function stopMovie(event:MouseEvent):void

{

videoStream.pause();

}


Recommended