ExternalDisplays
Comment:
- A first attempt to wrap some android classes and enable connection to and control of a Chromecast from b4a.
Requires:
Android Support V4 - android-support-v4
Android Support V7 AppCompat - android-support-v7-appcompat.jar
Android Support V7 MediaRouter - android-support-v7-mediarouter.jar
Don't forget to use the b4a ApplicationRes project attribute to include the 'res' folder of both of these libraries as well as the .jar files.
ControlIntent
Fields:
- ACTION As String
Remote playback media control action: Get media item playback status and progress information.
- ACTION_END_SESSION As String
Remote playback media control action: End session.
- ACTION_ENQUEUE As String
Remote playback media control action: Enqueue media item.
- ACTION_GET_SESSION_STATUS As String
Remote playback media control action: Get media session status information.
- ACTION_PAUSE As String
Remote playback media control action: Pause media playback.
- ACTION_PLAY As String
Remote playback media control action: Play media item.
- ACTION_REMOVE As String
Remote playback media control action: Remove media item from session's queue.
- ACTION_RESUME As String
Remote playback media control action: Resume media playback (unpause).
- ACTION_SEEK As String
Remote playback media control action: Seek media item to a new playback position.
- ACTION_START_SESSION As String
Remote playback media control action: Start session.
- ACTION_STOP As String
Remote playback media control action: Stop media playback (clear queue and unpause).
- CATEGORY_LIVE_AUDIO As String
Media control category: Live audio.
- CATEGORY_LIVE_VIDEO As String
Media control category: Live video.
- CATEGORY_REMOTE_PLAYBACK As String
Media control category: Remote playback.
- ERROR_INVALID_ITEM_ID As Int
Error code: The item id specified in the request was invalid.
- ERROR_INVALID_SESSION_ID As Int
Error code: The session id specified in the request was invalid.
- ERROR_UNKNOWN As Int
Error code: An unknown error occurred.
- ERROR_UNSUPPORTED_OPERATION As Int
Error code: The operation is not supported.
Display
Methods:
- GetCurrentSizeRanges As Point[]
Return the range of display sizes an application can expect to encounter under normal operation, as long as there is no physical change in screen size.
Return value is an array of Point objects where element 0 is the smallest display size and element 1 is the largest display size.
- GetDisplayId As Int
Gets the display id.
- GetFlags As Int
Returns a combination of flags that describe the capabilities of the display.
- GetMetrics As DisplayMetrics
Gets display metrics that describe the size and density of this display.
- GetName As String
Gets the name of the display.
- GetRealMetrics As DisplayMetrics
Gets display metrics based on the real size of this display.
- GetRealSize As Point
Gets the real size of the display without subtracting any window decor or applying any compatibility scale factors.
- GetRectSize As RectWrapper
Gets the size of the display as a rectangle, in pixels.
- GetRefreshRate As Float
Gets the refresh rate of this display in frames per second.
- GetSize As Point
Gets the size of the display, in pixels.
- IsInitialized As Boolean
- IsValid As Boolean
Returns true if this display is still valid, false if the display has been removed.
DisplayMetrics
Fields:
- DENSITY_DEFAULT As Int
- DENSITY_HIGH As Int
- DENSITY_LOW As Int
- DENSITY_MEDIUM As Int
- DENSITY_TV As Int
- DENSITY_XHIGH As Int
- DENSITY_XXHIGH As Int
Methods:
- Initialize
- IsInitialized As Boolean
- SetTo (DisplayMetrics1 As DisplayMetrics)
- SetToDefaults
Properties:
- Density As Float [read only]
The logical density of the display.
- DensityDpi As Int [read only]
The screen density expressed as dots-per-inch.
- HeightPixels As Int [read only]
The absolute height of the display in pixels.
- ScaledDensity As Float [read only]
A scaling factor for fonts displayed on the display.
- WidthPixels As Int [read only]
The absolute width of the display in pixels.
- Xdpi As Float [read only]
The exact physical pixels per inch of the screen in the X dimension.
- Ydpi As Float [read only]
The exact physical pixels per inch of the screen in the Y dimension.
ExternalDisplaysConstants
Fields:
- ControlIntent As ControlIntent
MediaControlIntent constants.
MediaItemStatus
Fields:
- PLAYBACK_STATE_BUFFERING As Int
Buffering or seeking to a new position.
Indicates that the media item has been temporarily interrupted to fetch more content. Playback will continue automatically when enough content has been buffered.
- PLAYBACK_STATE_CANCELED As Int
Indicates that the media item was explicitly removed from the queue by the application.
Items may be canceled and removed from the queue using the remove or stop action or by issuing another play action that has the side-effect of clearing the queue.
A canceled media item cannot be resumed.
- PLAYBACK_STATE_ERROR As Int
Playback halted or aborted due to an error.
Examples of errors are no network connectivity when attempting to retrieve content from a server, or expired user credentials when trying to play subscription-based content.
A media item in the error state cannot be resumed.
- PLAYBACK_STATE_FINISHED As Int
Indicates that the media item played to the end of the content and finished normally.
A finished media item cannot be resumed.
- PLAYBACK_STATE_INVALIDATED As Int
Indicates that the media item was invalidated permanently and involuntarily. This state is used to indicate that the media item was invalidated and removed from the queue because the session to which it belongs was invalidated (typically by another application taking control of the route).
When invalidation occurs, the application should generally wait for the user to perform an explicit action, such as clicking on a play button in the UI, before creating a new media session to avoid unnecessarily interrupting another application that may have just started using the route.
An invalidated media item cannot be resumed.
- PLAYBACK_STATE_PAUSED As Int
Indicates that playback of the media item has been paused. Playback can be resumed using the resume action.
- PLAYBACK_STATE_PENDING As Int
Indicates that the media item has not yet started playback but will be played eventually.
- PLAYBACK_STATE_PLAYING As Int
Indicates that the media item is currently playing.
Methods:
- GetContentDuration As Long
Gets the total duration of the content to be played as a long integer number of milliseconds.
- GetContentPosition As Long
Gets the content playback position as a long integer number of milliseconds from the beginning of the content.
Return type: @return:
- GetPlaybackState As Int
Gets the playback state of the media item.
- GetTimestamp As Long
Gets the timestamp associated with the status information in milliseconds since boot in the elapsedRealtime() time base.
- IsInitialized As Boolean
MediaRouteButton
Methods:
- BringToFront
- GetRouteSelector As MediaRouteSelector
Gets the media route selector for filtering the routes that the user can select using the media route chooser dialog.
- Initialize
- Invalidate
- Invalidate2 (arg0 As Rect)
- Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- IsInitialized As Boolean
- RemoveView
- RequestFocus As Boolean
- SendToBack
- SetBackgroundImage (arg0 As Bitmap)
- SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
- SetRouteSelector (MediaRouteSelector1 As MediaRouteSelector)
- ShowDialog As Boolean
Show the route chooser or controller dialog.
If the default route is selected or if the currently selected route does not match the selector, then shows the route chooser dialog.
Otherwise shows the route controller dialog to offer the user a choice to disconnect from the route or perform other control actions such as setting the route's volume.
Returns True if the dialog was actually shown.
Properties:
- Background As Drawable
- Color As Int [write only]
- Enabled As Boolean
- Height As Int
- Left As Int
- Tag As Object
- Top As Int
- Visible As Boolean
- Width As Int
MediaRouteSelector
Methods:
- Contains (MediaRouteSelector1 As MediaRouteSelector) As Boolean
Returns True if this MediaRouteSelector contains all of the capabilities described by MediaRouteSelector1.
- GetControlCategories As String[]
Gets the list of media control categories in the selector.
- HasControlCategory (ControlCategory As String) As Boolean
Returns True if the selector contains the specified category.
- IsEmpty As Boolean
Returns True if the selector does not specify any capabilities.
- IsInitialized As Boolean
- IsValid As Boolean
Returns True if the selector has all of the required fields.
MediaRouteSelectorBuilder
Methods:
- AddControlCategory (ControlCategory As String) As MediaRouteSelectorBuilder
Adds a media control category to the builder.
- AddMediaRouteSelector (MediaRouteSelector1 As MediaRouteSelector) As MediaRouteSelectorBuilder
Adds the contents of an existing media route selector to the builder.
- Build As MediaRouteSelector
Builds the media route selector.
- Initialize
Creates an empty media route selector builder.
- Initialize2 (MediaRouteSelector1 As MediaRouteSelector)
Creates a media route selector descriptor builder whose initial contents are copied from an existing selector.
- IsInitialized As Boolean
MediaRouter
Fields:
- AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE As Int
Ignore the default route.
- CALLBACK_FLAG_PERFORM_ACTIVE_SCAN As Int
Actively scan for routes while this callback is registered.
- CALLBACK_FLAG_REQUEST_DISCOVERY As Int
Request that route discovery be performed while this callback is registered.
- CALLBACK_FLAG_UNFILTERED_EVENTS As Int
Do not filter route events.
Methods:
- AddCallback (EventName As String, MediaRouteSelector1 As MediaRouteSelector, Flags As Int) As MediaRouterCallback
Registers a MediaRouterCallback to discover routes that match the selector and to receive events (defined by Flags) when they change.
Returns a reference to the MediaRouterCallback which can be passed to RemoveCallback to remove the listener.
- AddCallback2 (EventName As String, MediaRouteSelector1 As MediaRouteSelector) As MediaRouterCallback
Registers a MediaRouterCallback to discover routes that match the selector and to receive events when they change.
Returns a reference to the MediaRouterCallback which can be passed to RemoveCallback to remove the listener.
- GetDefaultRoute As MediaRouterRouteInfo
Gets the default route for playing media content on the system.
- GetSelectedRoute As MediaRouterRouteInfo
- Initialize
Gets the currently selected route.
- IsInitialized As Boolean
- IsRouteAvailable (MediaRouteSelector1 As MediaRouteSelector, Flags As Int) As Boolean
Returns True if there is a route that matches the specified selector.
- RemoveCallback (MediaRouterCallback1 As Callback)
- SelectRoute (MediaRouterRouteInfo1 As RouteInfo)
Selects the specified route.
- UpdateSelectedRoute (MediaRouteSelector1 As MediaRouteSelector) As MediaRouterRouteInfo
Returns the selected route if it matches the specified selector, otherwise selects the default route and returns it.
MediaRouterCallback
Events:
- RouteSelected (MediaRouter1 As MediaRouter, MediaRouterRouteInfo1 As MediaRouterRouteInfo)
- RouteUnselected (MediaRouter1 As MediaRouter, MediaRouterRouteInfo1 As MediaRouterRouteInfo)
Methods:
MediaRouterControlRequestCallback
Methods:
MediaRouterProviderInfo
Methods:
MediaRouterRouteInfo
Fields:
- PLAYBACK_TYPE_LOCAL As Int
The default playback type, "local", indicating the presentation of the media is happening on the same device (e.g. a phone, a tablet) as where it is controlled from.
- PLAYBACK_TYPE_REMOTE As Int
A playback type indicating the presentation of the media is happening on a different device (i.e. the remote device) than where it is controlled from.
- PLAYBACK_VOLUME_FIXED As Int
Playback information indicating the playback volume is fixed, i.e. it cannot be controlled from this object.
An example of fixed playback volume is a remote player, playing over HDMI where the user prefers to control the volume on the HDMI sink, rather than attenuate at the source.
- PLAYBACK_VOLUME_VARIABLE As Int
Playback information indicating the playback volume is variable and can be controlled from this object.
Methods:
- GetDescription As String
Gets the user-visible description of the route.
- GetId As String
Gets the unique id of the route.
- GetName As String
Gets the user-visible name of the route.
- GetPlaybackStream As Int
Gets the audio stream over which the playback associated with this route is performed.
- GetPlaybackType As Int
Gets the type of playback associated with this route.
(PLAYBACK_TYPE_LOCAL or PLAYBACK_TYPE_REMOTE).
- GetPresentationDisplay As Display
Gets the Display that should be used by the application to show a Presentation on an external display when this route is selected.
- GetProvider As MediaRouterProviderInfo
Gets information about the provider of this media route.
- GetVolume As Int
Gets the current volume for this route.
- GetVolumeHandling As Int
Gets information about how volume is handled on the route.
- GetVolumeMax As Int
Gets the maximum volume at which the playback associated with this route is performed.
- IsConnecting As Boolean
Returns True if the route is in the process of connecting and is not yet ready for use.
- IsDefault As Boolean
Returns True if this route is the default route.
- IsEnabled As Boolean
Returns True if this route is enabled and may be selected.
- IsInitialized As Boolean
- IsSelected As Boolean
Returns True if this route is currently selected.
- MatchesSelector (MediaRouteSelector1 As MediaRouteSelector) As Boolean
Returns True if the route supports at least one of the capabilities described by a media route selector.
- RequestSetVolume (Volume As Int)
Requests a volume change for this route asynchronously.
- RequestUpdateVolume (Delta As Int)
Requests an incremental volume update for this route asynchronously.
- Select
Selects this media route.
- SupportsControlAction (Category As String, Action As String) As Boolean
Returns True if the route supports the specified media control category and action.
- SupportsControlCategory (Category As String) As Boolean
Returns True if the route supports the specified media control category.
MediaSessionStatus
Fields:
- SESSION_STATE_ACTIVE As Int
Indicates that the media session is active and in control of the route.
- SESSION_STATE_ENDED As Int
Indicates that the media session was ended normally using the end session action.
- SESSION_STATE_INVALIDATED As Int
Indicates that the media session was invalidated involuntarily due to another session taking control of the route.
Methods:
- GetSessionState As Int
Gets the session state.
- GetTimestamp As Long
Gets the timestamp associated with the status information in milliseconds since boot in the elapsedRealtime() time base.
- IsInitialized As Boolean
- IsQueuePaused As Boolean
Returns true if the session's queue is paused.
Point
Methods:
- Equals (X As Int, Y As Int) As Boolean
Returns true if the point's coordinates equal (X, Y).
- Initialize (X As Int, Y As Int)
- Initialize2 (Point1 As Point)
- Initialize3
- IsInitialized As Boolean
- Negate
Negate the point's coordinates.
- Offset (Dx As Int, Dy As Int)
Offset the point's coordinates by Dx, Dy.
- Set (X As Int, Y As Int)
Properties:
- X As Int [read only]
- Y As Int [read only]
RemotePlaybackClient
Events:
- ItemActionError (ErrorMessage As String, ErrorCode As Int, Tag As Object)
- ItemActionResult (SessionId As String, MediaSessionStatus1 As MediaSessionStatus, ItemId As String, MediaItemStatus1 As MediaItemStatus, Tag As Object)
- SessionActionError (ErrorMessage As String, ErrorCode As Int, Tag As Object)
- SessionActionResult (SessionId As String, MediaSessionStatus1 As MediaSessionStatus, Tag As Object)
- StatusItemStatusChanged (SessionId As String, MediaSessionStatus1 As MediaSessionStatus, ItemId As String, MediaItemStatus1 As MediaItemStatus, Tag As Object)
- StatusSessionChanged (SessionId As String)
- StatusSessionStatusChanged (SessionId As String, MediaSessionStatus1 As MediaSessionStatus, Tag As Object)
Methods:
- EndSession (Tag As Object)
Sends a request to end the media playback session.
- Enqueue (MediaResourceUri As String, MimeType As String, PositionMillis As Long, Tag As Object)
Sends a request to enqueue a media item.
- GetSessionId As String
Gets the current session id if there is one.
- GetSessionStatus (Tag As Object)
Sends a request to get the status of the media playback session.
- GetStatus (ItemId As String, Tag As Object)
Sends a request to get the status of a media item.
- HasSession As Boolean
Returns True if the client currently has a session.
- Initialize (EventName As String, MediaRouterRouteInfo1 As RouteInfo)
Creates a remote playback client for a route.
- IsInitialized As Boolean
- IsQueuingSupported As Boolean
Returns True if the route supports queuing features.
- IsRemotePlaybackSupported As Boolean
Returns True if the route supports remote playback.
- IsSessionManagementSupported As Boolean
Returns true if the route supports session management features.
- Pause (Tag As Object)
Sends a request to pause media playback.
- Play (MediaResourceUri As String, MimeType As String, PositionMillis As Long, Tag As Object)
Sends a request to play a media resource.
- Release
Releases resources owned by the client.
- Remove (ItemId As String, Tag As Object)
Sends a request to remove a media item from the queue.
- Resume (Tag As Object)
Sends a request to resume (unpause) media playback.
- Seek (ItemId As String, PositionMillis As Long, Tag As Object)
Sends a request to seek to a new position in a media item.
- SetSessionId (SessionId As String)
Sets the current session id.
- SetStatusCallback (Tag As Object)
Sets a callback that should receive status updates when the state of media sessions or media items created by this instance of the remote playback client changes.
- StartSession (Tag As Object)
Sends a request to start a new media playback session.
- Stop (Tag As Object)
Sends a request to stop media playback and clear the media playback queue.