View comments | RSS feed

Media class (Flash Professional only)

Inheritance MovieClip > UIObject class > UIComponent class > Media

ActionScript Class Names mx.controls.MediaController, mx.controls.MediaDisplay, mx.controls.MediaPlayback

Each component class has a version property, which is a class property. Class properties are available only for the class itself. The version property returns a string that indicates the version of the component. To access this property, use the following code:

trace(mx.controls.MediaPlayback.version);

NOTE

 

The code trace(myMediaInstance.version); returns undefined.

Method summary for the Media class

The following table lists methods of the Media class.

Method

Components

Description

Media.addCuePoint()

MediaDisplay, MediaPlayback

Adds a cue point object to the component instance.

Media.associateController()

MediaDisplay

Associates a MediaDisplay instance with a MediaController instance.

Media.associateDisplay()

MediaController

Associates a MediaController instance with a MediaDisplay instance.

Media.displayFull()

MediaPlayback

Converts the component instance to full-screen playback mode.

Media.displayNormal()

MediaPlayback

Converts the component instance back to its original screen size.

Media.getCuePoint()

MediaDisplay, MediaPlayback

Returns a cue point object.

Media.pause()

MediaDisplay, MediaPlayback

Pauses the playhead at its current location in the media timeline.

Media.play()

MediaDisplay, MediaPlayback

Plays the media associated with the component instance at a given starting point.

Media.removeAllCuePoints()

MediaDisplay, MediaPlayback

Deletes all cue point objects associated with a given component instance.

Media.removeCuePoint()

MediaDisplay, MediaPlayback

Deletes a specified cue point associated with a given component instance.

Media.setMedia()

MediaDisplay, MediaPlayback

Sets the media type and path to the specified media type.

Media.stop()

MediaDisplay, MediaPlayback

Stops the playhead and moves it to position 0, which is the beginning of the media.

Property summary for the Media class

The following table lists properties of the Media class.

Property

Components

Description

Media.activePlayControl

MediaController

Determines the component state when loaded at runtime.

Media.aspectRatio

MediaDisplay, MediaPlayback

Determines if the component instance maintains its video aspect ratio.

Media.autoPlay

MediaDisplay, MediaPlayback

Determines if the component instance immediately starts to buffer and play.

Media.autoSize

MediaDisplay, MediaPlayback

Determines the size of the media-viewing portion of the MediaDisplay or MediaPlayback component.

Media.backgroundStyle

MediaController

Determines if the component instance draws its chrome background.

Media.bytesLoaded

MediaDisplay, MediaPlayback

Read-only; the number of bytes loaded that are available for playing.

Media.bytesTotal

MediaDisplay, MediaPlayback

The number of bytes to be loaded into the component instance.

Media.contentPath

MediaDisplay, MediaPlayback

A string that holds the relative path and filename of the media to be streamed and played.

Media.controllerPolicy

MediaController, MediaPlayback

Determines whether the controller is hidden when instantiated and only appears when the user moves the mouse over the controller's collapsed state.

Media.controlPlacement

MediaPlayback

Determines where the component's controls are positioned.

Media.cuePoints

MediaDisplay, MediaPlayback

An array of cue point objects that have been assigned to a given component instance.

Media.horizontal

MediaController

Determines the orientation of the component instance.

Media.mediaType

MediaDisplay, MediaPlayback

Determines the type of media to be played.

Media.playheadTime

MediaDisplay, MediaPlayback

Holds the current position of the playhead (in seconds) for the media timeline that is playing.

Media.playing

MediaDisplay, MediaPlayback, MediaController

For MediaDisplay and MediaPlayback, this property is read-only and returns a Boolean value to indicate whether a given component instance is playing media. For MediaController, this property is read/write and controls the image (playing or paused) displayed on the Play/Pause button of the controller.

Media.preferredHeight

MediaDisplay, MediaPlayback

The default value of the height of a FLV file.

Media.preferredWidth

MediaDisplay, MediaPlayback

The default value of the width of a FLV file.

Media.totalTime

MediaDisplay, MediaPlayback

An integer that indicates the total length of the media, in seconds.

Media.volume

MediaDisplay, MediaPlayback

An integer from 0 (minimum) to 100 (maximum) that represents the volume level.

Event summary for the Media class

The following table lists events of the Media class.

Event

Components

Description

Media.change

MediaDisplay, MediaPlayback

Broadcast continuously while media is playing.

Media.click

MediaController, MediaPlayback

Broadcast when the user clicks the Play/Pause button.

Media.complete

MediaDisplay, MediaPlayback

Notification that the playhead has reached the end of the media.

Media.cuePoint

MediaDisplay, MediaPlayback

Notification that the playhead has reached a given cue point.

Media.playheadChange

MediaController, MediaPlayback

Broadcast by the component instance when a user moves the playback slider or clicks the Go to Beginning or Go to End button.

Media.progress

MediaDisplay, MediaPlayback

Generated continuously until the media has downloaded completely.

Media.scrubbing

MediaController,

MediaPlayback

Generated when the playhead is dragged.

Media.volume

MediaController, MediaPlayback

Broadcast when the user adjusts the volume.


Version 8

Comments


d_wood said on Feb 21, 2006 at 11:38 AM :
I've noticed that, with certain FLV files, playing completes, but the "complete" event is never sent.

This condition is distinguished in a few ways: the playhead comes almost to the end of the movie, but not quite there. Although actual playing of video stops, the MediaDisplay component indicates that it's still playing. The playheadTime reads the same with every request. If you manually move the playhead to the end while in this condition, the "complete" event will finally be sent, but this is the only way it will happen.

This is probably a flash bug, but all users who depend on end-of-movie events or cue points should be aware of it, and they're most likely to see such a detail here, on this page.

I haven't found any further information about this, but it is 100% reproducible for me based on the FLV used. Possible workarounds: write a function called at intervals to detect the condition...
d_wood said on Feb 21, 2006 at 11:53 AM :
Note that if you are trying to implement a "playlist," you may run into trouble using the "complete" event (sent by the MediaDisplay) to start playing another video.

The key is that both you _and_ the MediaController would then be listening for that "complete" event, and there is no guarantee you'll get it _after_ the controller. The controller uses the event to switch the button state from playing to paused once a movie is finished. If you use the event to play another video, and _then_ the controller's event handler runs, you'll notice that your video plays but the button/display in the controller is in the "paused" state.

This is kind of lame. It looks unprofessional, but also to pause, users will have to click once to get it into the playing state, and again to actually pause it.

You may also note that whatever you try to do in the complete event handler to fix this (i.e. call play, set playing to true) does not work.

One possible workaround is to schedule an interval using setInterval to do the work of playing the next video (though when I did this, I also had to manually play the video, and set the playing state in the controller to true as well, not sure why). Call this from "complete", and set it to run in a few hundred milliseconds, after the event handler has completed (but make sure that one-time event unschedules itself!).
No screen name said on Dec 14, 2006 at 10:47 PM :
Does anyone know how to make the mediaDisplay, start playing a flv at the begining after it has been played? The mediaDisplay is also streaming the flv.

myMediaDisplay.play(); // just pauses at the end of the movie
myMediaDisplay.play(0); // just pauses at the end of the movie
myMediaDisplay.play(1); // starts one second after the movie
Zubaz said on Jan 24, 2007 at 4:17 PM :
It should be noted that you can't setMedia on more than Media objects at any given time. The third will fail.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00003771.html