Media

Media Components

Table of Contents

Camcorder

A component to record a video using the device's camcorder. After the video is recorded, the name of the file on the phone containing the clip is available as an argument to the AfterRecording event. The file name can be used, for example, to set the source property of a VideoPlayer component.

Properties

none

Events

AfterRecording(text clip)
Indicates that a video was recorded with the camera and provides the path to the stored picture.

Methods

RecordVideo()
Records a video, then raises the AfterRecoding event.

Camera

Use a camera component to take a picture on the phone.

Camera is a non-visible component that takes a picture using the device's camera. After the picture is taken, the path to the file on the phone containing the picture is available as an argument to the AfterPicture event. The path can be used, for example, as the Picture property of an Image component.

Properties

none

Methods

Events

AfterPicture(Text image)
Called after the picture is taken. The text argument image is the path that can be used to locate the image on the phone.
TakePicture()
Opens the phone's camera to allow a picture to be taken, then raises the AfterPicture event.

ImagePicker

A special-purpose button. When the user taps an image picker, the device's image gallery appears, and the user can choose an image. After an image is picked, it is saved on the SD card and the ImageFile property will be the name of the file where the image is stored. In order to not fill up storage, a maximum of 10 images will be stored. Picking more images will delete previous images, in order from oldest to newest.

Properties

BackgroundColor
Color for image picker background.
Enabled
If set, user can tap image picker to cause action.
FontBold
If set, image picker button text is displayed in bold.
FontItalic
If set, image picker button text is displayed in italics.
FontSize
Point size for image picker button text.
FontTypeface
Font family for image picker button text.
Height
image picker button height (y-size).
Width
image picker button width (x-size).
Image
Image to display on image picker button.
Selection
Path to the file containing the image that was selected.
Text
Text to display on image picker button.
TextAlignment
Left, center, or right.
TextColor
Color for image picker button text.
Visible
Specifies whether the component should be visible on the screen. Value is true if the component is showing and false if hidden.

Events

AfterPicking()
User selected an item from the image picker.
BeforePicking()
User has tapped the image picker but hasn't yet selected an item.
GotFocus()
Image picker became the focused component.
LostFocus()
Image picker is no longer the focused component.

Methods

Open()
Opens the picker, as though the user clicked on it.

Player

Use a player component to play an audio or video file, or to vibrate the phone.

Player is a non-visible component that plays audio or video and controls phone vibration. The name of a media file is specified in the Source property, which can be set in the Designer or in the Blocks Editor. The length of time for a vibration is specified in the Blocks Editor in milliseconds (thousandths of a second).

See Android Supported Media Formats for more information on which types of files you can use.

Use a player component for playing long sound files, video files, and vibrating the phone. For playing short sound files, such as sound effects, use a Sound component instead.

Properties

IsLooping
Whether the media is looping
IsPlaying
Whether the media is playing
Source
Audio or video file associated with this player.
Volume
Sets the volume to a number between 0 and 100

Events

Completed()
Indicates that the media has reached the end

Methods

Pause()
Pauses playing the audio or video file.
Start()
Starts playing the audio or video file.
Stop()
Stops playing the audio or video file.
Vibrate(number milliseconds)
Activate the phone's vibration motor for the given number of milliseconds.

Sound

Use a sound component to play an audio file, or to vibrate the phone.

Sound is a non-visible component that plays sound files and vibrates for the number of milliseconds (thousandths of a second) specified in the Blocks Editor. The name of the sound file to play can be specified either in the Designer or in the Blocks Editor.

See Android Supported Media Formats for more information on which types of files you can use.

This component is best for short sound files, such as sound effects, while the Player component is more efficient for longer sounds, such as songs.

Properties

Source
Audio file associated with this sound
MinimumInterval
Minimum time before sound is repeated

Events

none

Methods

Pause()
Pauses playing the audio file.
Play()
Starts playing the audio file.
Resume()
Resumes playing a paused audio file.
Stop()
Stops playing the audio file.
Vibrate(number millisecs)
Activate the phone's vibration motor for the given number of milliseconds.

VideoPlayer

Use a VideoPlayer component to play a video file.

Video player is a media component that plays videos. A video player appears in your app as a rectangle. If the user taps the rectangle, media controls appear: play/pause, skip ahead, and skip backward. Your app can control playback behavior by calling the Start, Pause, and SeekTo<.code> methods.

Video files should be in 3GPP (.3gp), or MPEG-4 (.mp4) format. For more details about formats, see Android Supported Media Formats.

App Inventor accepts video files up to 1 MB in size and limits the total size of an app to 5 MB, not all of which is available for media files. If your media files are too large, you might get errors when packaging or installing your app, in which case you should reduce the number of media files or their sizes. Video editing software, such as Windows Movie Maker or Apple iMovie, can help you decrease the size of videos by shortening them or re-encoding them into more compact formats.

Properties

Source
Video file associated with this player.
Visible
If set, VideoPlayer is visible.
FullScreen
Height
Width

Events

Completed()
Indicates that the video has reached the end

Methods

Pause()
Pauses playing the video file.
Start()
Starts playing the video file.
SeekTo(number millisecs)
Seeks to the requested time )specified in milliseconds) in the video.
number GetDuration()
Returns the duration of the video in milliseconds.