Media

« Back to index

Media

Table of Contents:

Camcorder

Camcorder icon

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(clip)
Indicates that a video was recorded with the camera and provides the path to the stored video.

Methods

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

Camera

Camera icon

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

Events

AfterPicture(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.

Methods

TakePicture()
Takes a picture, then raises the AfterPicture event.

ImagePicker

A special-purpose button. When the user taps an ImagePicker, the device’s image gallery appears, and the user can choose an image. After an image is picked, it is saved, and the Selection 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
Specifies the ImagePicker’s background color as an alpha-red-green-blue integer. If an Image has been set, the color change will not be visible until the Image is removed.
Enabled
Specifies whether the ImagePicker should be active and clickable.
FontBold
Specifies whether the text of the ImagePicker should be bold. Some fonts do not support bold.
FontItalic
Specifies whether the text of the ImagePicker should be italic. Some fonts do not support italic.
FontSize
Specifies the text font size of the ImagePicker, measured in sp(scale-independent pixels).
FontTypeface
Specifies the text font face of the ImagePicker as default, serif, sans serif, or monospace.
Height
Specifies the ImagePicker’s vertical height, measured in pixels.
HeightPercent
Specifies the ImagePicker’s vertical height as a percentage of the Screen’s Height.
Image
Specifies the path of the ImagePicker’s image. If there is both an Image and a BackgroundColor specified, only the Image will be visible.
Selection
Path to the file containing the image that was selected.
Shape
Specifies the shape of the ImagePicker. The valid values for this property are 0 (default), 1 (rounded), 2 (rectangle), and 3 (oval). The Shape will not be visible if an Image is used.
ShowFeedback
Specifies if a visual feedback should be shown when a ImagePicker with an assigned Image is pressed.
Text
Specifies the text displayed by the ImagePicker.
TextAlignment
Specifies the alignment of the ImagePicker’s text. Valid values are: 0 (normal; e.g., left-justified if text is written left to right), 1 (center), or 2 (opposite; e.g., right-justified if text is written left to right).
TextColor
Specifies the text color of the ImagePicker as an alpha-red-green-blue integer.
Visible
Specifies whether the ImagePicker should be visible on the screen. Value is true if the ImagePicker is showing and false if hidden.
Width
Specifies the horizontal width of the ImagePicker, measured in pixels.
WidthPercent
Specifies the horizontal width of the ImagePicker as a percentage of the Screen’s Width.

Events

AfterPicking()
Event to be raised after the ImagePicker activity returns its result and the properties have been filled in.
BeforePicking()
Event to raise when the ImagePicker is clicked or the picker is shown using the Open method. This event occurs before the picker is displayed, and can be used to prepare the picker before it is shown.
GotFocus()
Indicates the cursor moved over the ImagePicker so it is now possible to click it.
LostFocus()
Indicates the cursor moved away from the ImagePicker so it is now no longer possible to click it.
TouchDown()
Indicates that the ImagePicker was pressed down.
TouchUp()
Indicates that the ImagePicker has been released.

Methods

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

Player

Multimedia component that plays audio and controls phone vibration. The name of a multimedia 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).

For supported audio formats, see Android Supported Media Formats.

This component is best for long sound files, such as songs, while the Sound component is more efficient for short files, such as sound effects.

Properties

IsPlaying
Reports whether the media is playing.
Loop
If true, the Player will loop when it plays. Setting Loop while the player is playing will affect the current playing.
PlayOnlyInForeground
If true, the Player will pause playing when leaving the current screen; if false (default option), the Player continues playing whenever the current screen is displaying or not.
Source
Sets the audio source.
Volume
Sets the volume property to a number between 0 and 100.

Events

Completed()
Indicates that the media has reached the end
OtherPlayerStarted()
This event is signaled when another player has started (and the current player is playing or paused, but not stopped).

Methods

Pause()
Suspends playing the media if it is playing.
Start()
Plays the media. If it was previously paused, the playing is resumed. If it was previously stopped, it starts from the beginning.
Stop()
Stops playing the media and seeks to the beginning of the song.
Vibrate(milliseconds)
Vibrates for specified number of milliseconds.

Sound

A multimedia component that plays sound files and optionally 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.

For supported sound file formats, see Android Supported Media Formats.

This Sound 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

MinimumInterval
Specifies the minimum interval required between calls to Play, in milliseconds. Once the sound starts playing, all further Play calls will be ignored until the interval has elapsed.
Source
The name of the sound file. Only certain formats are supported. See http://developer.android.com/guide/appendix/media-formats.html.

Events

None

Methods

Pause()
Pauses playing the sound if it is being played.
Play()
Plays the sound.
Resume()
Resumes playing the sound after a pause.
Stop()
Stops playing the sound if it is being played.
Vibrate(millisecs)
Vibrates for the specified number of milliseconds.

SoundRecorder

SoundRecorder icon

Multimedia component that records audio.

Properties

SavedRecording
Specifies the path to the file where the recording should be stored. If this property is the empty string, then starting a recording will create a file in an appropriate location. If the property is not the empty string, it should specify a complete path to a file in an existing directory, including a file name with the extension .3gp.

Events

AfterSoundRecorded(sound)
Provides the location of the newly created sound.
StartedRecording()
Indicates that the recorder has started, and can be stopped.
StoppedRecording()
Indicates that the recorder has stopped, and can be started again.

Methods

Start()
Starts recording.
Stop()
Stops recording.

SpeechRecognizer

SpeechRecognizer icon

Use a SpeechRecognizer component to listen to the user speaking and convert the spoken sound into text using the device’s speech recognition feature.

Properties

Result
Returns the last text produced by the recognizer.
UseLegacy
If true, a separate dialog is used to recognize speech (the default). If false, speech is recognized in the background and updates are received as it recognizes words. AfterGettingText may get several calls with partial set to true. Once sufficient time has elapsed since the last utterance, or StopListening is called, the last string will be returned with partial set to false to indicate that it is the final recognized string and no more data will be provided until recognition is again started. See AfterGettingText for more details on partial speech recognition.

Events

AfterGettingText(result,partial)
Simple event to raise after the SpeechRecognizer has recognized speech. If UseLegacy is true, then this event will only happen once at the very end of the recognition. If UseLegacy is false, then this event will run multiple times as the SpeechRecognizer incrementally recognizes speech. In this case, partial will be true until the recognized speech has been finalized (e.g., the user has stopped speaking), in which case partial will be false.
BeforeGettingText()
Simple event to raise when the SpeechRecognizer is invoked but before its activity is started.

Methods

GetText()
Asks the user to speak, and converts the speech to text. Signals the AfterGettingText event when the result is available.
Stop()
Function used to forcefully stop listening speech in cases where SpeechRecognizer cannot stop automatically. This function works only when the UseLegacy property is set to false.

TextToSpeech

The TextToSpeech component speaks a given text aloud. You can set the pitch and the rate of speech.

You can also set a language by supplying a language code. This changes the pronunciation of words, not the actual language spoken. For example, setting the Language to French and speaking English text will sound like someone speaking English (en) with a French accent.

You can also specify a country by supplying a Country code. This can affect the pronunciation. For example, British English (GBR) will sound different from US English (USA). Not every country code will affect every language.

The languages and countries available depend on the particular device, and can be listed with the AvailableLanguages and AvailableCountries properties.

Properties

AvailableCountries
List of the country codes available on this device for use with TextToSpeech. Check the Android developer documentation under supported languages to find the meanings of these abbreviations.
AvailableLanguages
List of the languages available on this device for use with TextToSpeech. Check the Android developer documentation under supported languages to find the meanings of these abbreviations.
Country
Country code to use for speech generation. This can affect the pronunciation. For example, British English (GBR) will sound different from US English (USA). Not every country code will affect every language.
Language
Sets the language for TextToSpeech. This changes the way that words are pronounced, not the actual language that is spoken. For example, setting the language to French and speaking English text will sound like someone speaking English with a French accent.
Pitch
Sets the speech pitch for the TextToSpeech.

The values should be between 0 and 2 where lower values lower the tone of synthesized voice and greater values raise it.

The default value is 1.0 for normal pitch.

Result
Returns true if the text was successfully converted to speech, otherwise false.
SpeechRate
Sets the SpeechRate for TextToSpeech.

The values should be between 0 and 2 where lower values slow down the pitch and greater values accelerate it.

The default value is 1.0 for normal speech rate.

Events

AfterSpeaking(result)
Event to raise after the message is spoken. The result will be true if the message is spoken successfully, otherwise it will be false.
BeforeSpeaking()
Event to raise when Speak is invoked, before the message is spoken.

Methods

Speak(message)
Speaks the given message.

VideoPlayer

A multimedia component capable of playing videos. When the application is run, the VideoPlayer will be displayed as a rectangle on-screen. If the user touches the rectangle, controls will appear to play/pause, skip ahead, and skip backward within the video. The application can also control behavior by calling the Start, Pause, and SeekTo methods.

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

App Inventor only permits video files under 1 MB and limits the total size of an application to 5 MB, not all of which is available for media (video, audio, and sound) files. If your media files are too large, you may get errors when packaging or installing your application, in which case you should reduce the number of media files or their sizes. Most video editing software, such as Windows Movie Maker and Apple iMovie, can help you decrease the size of videos by shortening them or re-encoding the video into a more compact format.

You can also set the media source to a URL that points to a streaming video, but the URL must point to the video file itself, not to a program that plays the video.

Properties

FullScreen
Sets whether the video should be shown in fullscreen or not.
Height
Specifies the component’s vertical height, measured in pixels.
HeightPercent
Specifies the VideoPlayer’s vertical height as a percentage of the Screen’s Height.
Source
Sets the “path” to the video. Usually, this will be the name of the video file, which should be added in the Designer.
Visible
Specifies whether the VideoPlayer should be visible on the screen. Value is true if the VideoPlayer is showing and false if hidden.
Volume
Sets the volume property to a number between 0 and 100. Values less than 0 will be treated as 0, and values greater than 100 will be treated as 100.
Width
Specifies the component’s horizontal width, measured in pixels.
WidthPercent
Specifies the horizontal width of the VideoPlayer as a percentage of the Screen’s Width.

Events

Completed()
Indicates that the video has reached the end

Methods

GetDuration()
Returns duration of the video in milliseconds.
Pause()
Pauses playback of the video. Playback can be resumed at the same location by calling the Start method.
SeekTo(ms)
Seeks to the requested time (specified in milliseconds) in the video. If the video is paused, the frame shown will not be updated by the seek. The player can jump only to key frames in the video, so seeking to times that differ by short intervals may not actually move to different frames.
Start()
Plays the media specified by the Source.
Stop()
Resets to start of video and pauses it if video was playing.

YandexTranslate

Use this component to translate words and sentences between different languages. This component needs Internet access, as it will request translations to the Yandex.Translate service. Specify the source and target language in the form source-target using two letter language codes. So “en-es” will translate from English to Spanish while “es-ru” will translate from Spanish to Russian. If you leave out the source language, the service will attempt to detect the source language. So providing just “es” will attempt to detect the source language and translate it to Spanish.

This component is powered by the Yandex translation service. See http://api.yandex.com/translate/ for more information, including the list of available languages and the meanings of the language codes and status codes.

Note: Translation happens asynchronously in the background. When the translation is complete, the GotTranslation event is triggered.

Properties

ApiKey
The Yandex API Key to use. If set to DEFAULT the platform default key (if any) will be used. Otherwise should be set to a valid API key which can be obtained from https://tech.yandex.com/translate/. If the platform doesn’t have a default key and one isn’t provided here, an error will be raised.

Events

GotTranslation(responseCode,translation)
Event indicating that a request has finished and has returned data (translation).

Methods

RequestTranslation(languageToTranslateTo,textToTranslate)
By providing a target language to translate to (for instance, ‘es’ for Spanish, ‘en’ for English, or ‘ru’ for Russian), and a word or sentence to translate, this method will request a translation to the Yandex.Translate service. Once the text is translated by the external service, the event GotTranslation will be executed.

Note: Yandex.Translate will attempt to detect the source language. You can also specify prepending it to the language translation, e.g., es-ru will specify Spanish to Russian translation.