public class WZCameraView extends SurfaceView implements WZBroadcastAPI.VideoBroadcaster, WZBroadcastAPI.AdaptiveBroadcaster
WZCameraView
class provides a custom View class for previewing the video captured from
a camera device.Modifier and Type | Class and Description |
---|---|
static interface |
WZCameraView.PreviewStatusListener
Callback interface to use with
setPreviewStatusListener(PreviewStatusListener) |
Constructor and Description |
---|
WZCameraView(Context context)
Simple constructor to use when creating a view from code.
|
WZCameraView(Context context,
AttributeSet attrs)
Constructor that is called when inflating a view from XML.
|
Modifier and Type | Method and Description |
---|---|
void |
changeAdaptiveBitrate(int bitrate) |
void |
changeAdaptiveFramerate(int framerate) |
void |
clearView()
Clear the currently rendered frame from the view
|
WZSize |
getActiveFrameSize()
Returns the active video frame size which may differ from the requested frame size if the current scale mode is FILL_VIEW
|
int |
getAdaptiveBitrate() |
int |
getAdaptiveFramerate() |
static WZCamera[] |
getAvailableDeviceCameras()
Deprecated.
As of v1.1, this method has been moved to
WZCamera.getAvailableDeviceCameras() |
WZBroadcastConfig |
getBroadcastConfig()
Returns the configuration settings for an active broadcast session.
|
WZBroadcastAPI.VideoBroadcaster |
getBroadcaster()
Deprecated.
The WZCameraView class now implements the
WZBroadcastAPI.VideoBroadcaster interface
so you can use a WZCameraView instance directly in
WZBroadcastConfig.setVideoBroadcaster(WZBroadcastAPI.VideoBroadcaster)
e.g. broadcastConfig.setVideoBroadcaster(cameraView); |
WZStatus |
getBroadcasterStatus()
Returns the status for a broadcast component
|
WZCamera |
getCamera()
Returns the active camera
|
WZCamera |
getCameraByDirection(int direction)
Returns a camera instance based on it's id specifier
|
WZCamera |
getCameraById(int cameraId)
Returns a camera instance based on it's id specifier
|
static String |
getCameraInfo()
Deprecated.
As of v1.1, this method has been moved to
WZCamera.getCameraInfo() |
WZCamera[] |
getCameras()
Returns an array of
WZCamera instances for each camera device present |
static WZCamera[] |
getDeviceCameras()
Deprecated.
As of v1.1, this method has been moved to
WZCamera.getDeviceCameras() |
int |
getDeviceOrientation()
Deprecated.
As of v1.1, the preferred method for retrieving this information is
WZDeviceUtils.getDeviceOrientation(Context) in the WZDeviceUtils class |
int |
getFramerate()
Returns the currently configured video framerate
|
WZSize |
getFrameSize()
Returns the currently configured video frame size
|
static int |
getNumberOfDeviceCameras()
Deprecated.
As of v1.1, this method has been moved to
WZCamera.getNumberOfDeviceCameras() |
WZCamera |
getOtherCamera()
Returns the camera that is not currently active, if present
|
int |
getOtherCameraId()
Returns the id of the camera that is not currently active, if present
|
WZStatus |
getPreviewStatus()
Returns this view's preview status.
|
int |
getScaleMode() |
WZSize |
getScreenSize()
Returns the size of camera preview display
|
WZStatus |
getStatus()
Deprecated.
Use
getPreviewStatus() instead |
WZColor |
getVideoBackgroundColor() |
WZMediaConfig |
getVideoSourceConfig()
Returns configuration information for the video source
|
boolean |
isPaused()
Deprecated.
Use
isPreviewPaused() instead |
boolean |
isPreviewing()
Indicates if the camera preview display is active
getPreviewStatus().isRunning() and getPreviewStatus().getState == WZState.RUNNING |
boolean |
isPreviewPaused()
Indicates if the camera preview display was paused due to the onPause method begin called
|
boolean |
isPreviewReady()
Indicates if the camera preview has been fully initialized
|
boolean |
isSwitchCameraAvailable()
Indicates if current camera can be switched based on the state of any live streaming broadcast currently active and device presence.
|
boolean |
isSwitchCameraAvailable(WZMediaConfig mediaConfig)
Indicates if current camera can be switched based on the state of any live streaming broadcast currently active and device presence.
|
boolean |
isSwitchCameraAvailable(WZSize withFrameSize)
Indicates if current camera can be switched based on the state of any live streaming broadcast currently active and device presence.
|
boolean |
isVideoEnabled()
Indicates if a broadcast component is enabled or not
|
boolean |
isVideoPaused()
Indicates if a broadcast component is paused or not
|
void |
onConfigurationChanged(Configuration newConfig)
Called when the device configuration changes, typically to detect device orientation changes
|
void |
onLowMemory()
Called when the overall system is running low on memory,
and actively running processes should trim their memory usage.
|
void |
onPause()
This method can be called from the activity's
onPause() method to store the state of the
camera preview display before the application is sent to the background. |
void |
onResume()
|
WZStatus |
prepareForBroadcast(WZBroadcastConfig broadcastConfig)
This method is called to initialize each component of a broadcast.
|
void |
registerFrameListener(WZRenderAPI.VideoFrameListener frameListener)
Call to register an object instance implementing the
WZRenderAPI.VideoFrameListener interface
that can be used to capture content from the camera preview display |
void |
registerFrameRenderer(WZRenderAPI.VideoFrameRenderer frameRenderer)
Call to register an object instance implementing the
WZRenderAPI.VideoFrameRenderer interface
that can be used to render additional content, such as a logo, to the camera preview display |
WZCamera |
setCamera(int cameraId)
Sets the active camera
|
WZCamera |
setCamera(WZCamera camera)
Sets the active camera
|
WZCamera |
setCameraByDirection(int direction)
Sets the active camera based on the specified direction (front or back)
|
void |
setCameraConfig(WZMediaConfig previewConfig)
Update the frame size and framerate settings for the active camera with the corresponding values from the specified configuration
|
int |
setFramerate(int framerate)
Update the framerate for the active camera with the specified value
|
WZSize |
setFrameSize(int width,
int height)
Update the frame size for the active camera with the specified values
|
WZSize |
setFrameSize(WZSize frameSize)
Update the frame size for the active camera with the specified size
|
void |
setPreviewReadyListener(WZCameraView.PreviewStatusListener previewReadyListener)
Deprecated.
Use
setPreviewStatusListener(PreviewStatusListener) instead |
void |
setPreviewStatusListener(WZCameraView.PreviewStatusListener previewStatusListener)
Sets the callback instance to receive callback notifications when the camera preview is fully started
or stopped or an error occurred in the process.
|
void |
setScaleMode(int scaleMode) |
void |
setVideoBackgroundColor(WZColor videoBackgroundColor) |
void |
setVideoEnabled(boolean enabled)
Set or unset the flag indicating that a broadcast component is enabled
|
void |
setVideoPaused(boolean videoPaused)
Set or unset the flag indicating that a broadcast component is in a paused state
|
WZStatus |
startBroadcasting()
This method is called on each broadcast component to begin a live streaming broadcast.
|
WZCamera |
startPreview()
Start the camera preview display
|
WZCamera |
startPreview(WZCameraView.PreviewStatusListener previewStatusListener) |
WZCamera |
startPreview(WZMediaConfig cameraConfig)
Start the camera preview display using the values from the specified configuration for the camera frame size and framerate
|
WZCamera |
startPreview(WZMediaConfig cameraConfig,
WZCameraView.PreviewStatusListener previewStatusListener)
Start the camera preview display
|
WZStatus |
stopBroadcasting()
This method is called on each broadcast component to end a live streaming broadcast.
|
WZCamera |
stopPreview()
Stop the camera preview display
|
WZCamera |
stopPreview(WZCameraView.PreviewStatusListener previewStatusListener)
Stop the camera preview display
|
void |
surfaceChanged(SurfaceHolder holder,
int format,
int width,
int height)
Called immediately after any structural changes (format or size) have been made to the surface.
|
void |
surfaceCreated(SurfaceHolder surfaceHolder)
Called immediately after the surface is first created.
|
void |
surfaceDestroyed(SurfaceHolder holder)
Called immediately before a surface is being destroyed.
|
WZCamera |
switchCamera()
Changes the active camera being previewed to the alternate device camera, if available.
|
void |
unregisterFrameListener(WZRenderAPI.VideoFrameListener frameListener)
Call to unregister a previously registered frame listener
|
void |
unregisterFrameRenderer(WZRenderAPI.VideoFrameRenderer frameRenderer)
Call to unregister a previously registered frame listener
|
public WZCameraView(Context context, AttributeSet attrs)
context
- The Context the view is running in, through which it can access the current theme, resources, etc.attrs
- The attributes of the XML tag that is inflating the view.public WZCameraView(Context context)
context
- The Context the view is running in, through which it can access the current theme, resources, etc.public static int getNumberOfDeviceCameras()
WZCamera.getNumberOfDeviceCameras()
WZCamera.getNumberOfDeviceCameras()
public static WZCamera[] getDeviceCameras()
WZCamera.getDeviceCameras()
public static WZCamera[] getAvailableDeviceCameras()
WZCamera.getAvailableDeviceCameras()
public static String getCameraInfo()
WZCamera.getCameraInfo()
public int getDeviceOrientation()
WZDeviceUtils.getDeviceOrientation(Context)
in the WZDeviceUtils
classpublic void setPreviewStatusListener(WZCameraView.PreviewStatusListener previewStatusListener)
previewStatusListener
- An object that has implemented the PreviewStatusListener interfacepublic void setPreviewReadyListener(WZCameraView.PreviewStatusListener previewReadyListener)
setPreviewStatusListener(PreviewStatusListener)
insteadpublic WZStatus getPreviewStatus()
WZState.RUNNING
, or WZState.IDLE
otherwisepublic WZStatus getStatus()
getPreviewStatus()
insteadgetStatus
in interface WZBroadcastAPI.Broadcaster
public boolean isPreviewing()
getPreviewStatus().isRunning()
and getPreviewStatus().getState == WZState.RUNNING
public boolean isPreviewReady()
public boolean isPreviewPaused()
public boolean isPaused()
isPreviewPaused()
insteadpublic WZBroadcastAPI.VideoBroadcaster getBroadcaster()
WZBroadcastAPI.VideoBroadcaster
interface
so you can use a WZCameraView instance directly in
WZBroadcastConfig.setVideoBroadcaster(WZBroadcastAPI.VideoBroadcaster)
e.g. broadcastConfig.setVideoBroadcaster(cameraView);
public WZColor getVideoBackgroundColor()
public void setVideoBackgroundColor(WZColor videoBackgroundColor)
public WZMediaConfig getVideoSourceConfig()
WZBroadcastAPI.VideoBroadcaster
getVideoSourceConfig
in interface WZBroadcastAPI.VideoBroadcaster
public void setVideoEnabled(boolean enabled)
WZBroadcastAPI.VideoBroadcaster
setVideoEnabled
in interface WZBroadcastAPI.VideoBroadcaster
enabled
- true if the audio broadcast component should be enabled, false otherwisepublic boolean isVideoEnabled()
WZBroadcastAPI.VideoBroadcaster
isVideoEnabled
in interface WZBroadcastAPI.VideoBroadcaster
public void setVideoPaused(boolean videoPaused)
WZBroadcastAPI.VideoBroadcaster
setVideoPaused
in interface WZBroadcastAPI.VideoBroadcaster
videoPaused
- true if the video broadcast component should be placed in a paused state, false otherwisepublic boolean isVideoPaused()
WZBroadcastAPI.VideoBroadcaster
isVideoPaused
in interface WZBroadcastAPI.VideoBroadcaster
public WZBroadcastConfig getBroadcastConfig()
WZBroadcastAPI.Broadcaster
getBroadcastConfig
in interface WZBroadcastAPI.Broadcaster
public WZStatus getBroadcasterStatus()
WZBroadcastAPI.Broadcaster
getBroadcasterStatus
in interface WZBroadcastAPI.Broadcaster
public WZStatus prepareForBroadcast(WZBroadcastConfig broadcastConfig)
WZBroadcastAPI.Broadcaster
WZState.READY
or WZState.IDLE
and indicate the error in the status as well.prepareForBroadcast
in interface WZBroadcastAPI.Broadcaster
broadcastConfig
- The broadcast configurationWZState.READY
public WZStatus startBroadcasting()
WZBroadcastAPI.Broadcaster
WZState.RUNNING
or WZState.IDLE
and indicate the error in the status as wellstartBroadcasting
in interface WZBroadcastAPI.Broadcaster
WZState.RUNNING
public WZStatus stopBroadcasting()
WZBroadcastAPI.Broadcaster
WZState.IDLE
stopBroadcasting
in interface WZBroadcastAPI.Broadcaster
WZState.IDLE
public void changeAdaptiveBitrate(int bitrate)
changeAdaptiveBitrate
in interface WZBroadcastAPI.AdaptiveBroadcaster
public int getAdaptiveBitrate()
getAdaptiveBitrate
in interface WZBroadcastAPI.AdaptiveBroadcaster
public void changeAdaptiveFramerate(int framerate)
changeAdaptiveFramerate
in interface WZBroadcastAPI.AdaptiveBroadcaster
public int getAdaptiveFramerate()
getAdaptiveFramerate
in interface WZBroadcastAPI.AdaptiveBroadcaster
public WZCamera startPreview(WZMediaConfig cameraConfig, WZCameraView.PreviewStatusListener previewStatusListener)
public WZCamera startPreview(WZCameraView.PreviewStatusListener previewStatusListener)
public WZCamera startPreview(WZMediaConfig cameraConfig)
cameraConfig
- A configuration with frame size and framerate property values to usepublic WZCamera startPreview()
public WZCamera stopPreview(WZCameraView.PreviewStatusListener previewStatusListener)
public WZCamera stopPreview()
public void clearView()
public void setCameraConfig(WZMediaConfig previewConfig)
previewConfig
- A configuration with frame size and framerate property values to usepublic int getScaleMode()
public void setScaleMode(int scaleMode)
public WZSize getFrameSize()
public WZSize getActiveFrameSize()
public WZSize setFrameSize(int width, int height)
Note that the actual frame size resulting from this operation may vary from the specified frame size. If the active camera device does not support the specified frame size, the closest, larger frame size that is supported will be selected instead and indicated as the return value from this method.
width
- The width of the video frame size (pixels)height
- The height of the video frame size (pixels)public WZSize setFrameSize(WZSize frameSize)
Note that the actual frame size resulting from this call may vary from the specified frame size. If the active camera device does not support the specified frame size, the closest, larger frame size that is supported will be selected instead and indicated as the return value from this method.
frameSize
- The frame size specificationpublic int getFramerate()
public int setFramerate(int framerate)
Note that the actual framerate resulting from this call may vary from the specified framerate. If the active camera device does not support the specified framerate, the closest supported framerate will be selected instead and indicated as the return value from this method.
framerate
- The requested framerate (fps)public WZCamera[] getCameras()
WZCamera
instances for each camera device presentpublic WZCamera getCamera()
public WZCamera getCameraById(int cameraId)
cameraId
- the camera's unique id available via WZCamera.getCameraId()
public WZCamera getCameraByDirection(int direction)
direction
- WZCamera.DIRECTION_FRONT
, WZCamera##DIRECTION_FRONT
public WZCamera getOtherCamera()
public int getOtherCameraId()
public WZCamera setCamera(int cameraId)
cameraId
- the id of the camera to displaypublic WZCamera setCamera(WZCamera camera)
camera
- the camera to displaypublic WZCamera setCameraByDirection(int direction)
direction
- WZCamera.DIRECTION_FRONT
, WZCamera##DIRECTION_FRONT
public WZCamera switchCamera()
In order to switch the active camera while streaming, the alternate camera must support the video frame size of the currently active camera.
public boolean isSwitchCameraAvailable(WZSize withFrameSize)
In order to switch the active camera while streaming, the other camera must support the video frame size of the currently active camera.
withFrameSize
- if supplied, the result will only be true if the other camera supported the specified frame sizepublic boolean isSwitchCameraAvailable(WZMediaConfig mediaConfig)
In order to switch the active camera while streaming, the other camera must support the frane size of the currently active camera.
mediaConfig
- if supplied, the result will only be true if the other camera supported the video frame size indicated by the specified configrationpublic boolean isSwitchCameraAvailable()
In order to switch the active camera while streaming, the other camera must support the video frame size of the currently active camera.
public void onConfigurationChanged(Configuration newConfig)
newConfig
- The new device configuration.
https://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges
public void onLowMemory()
https://developer.android.com/reference/android/app/Activity.html#onLowMemory()
public void surfaceCreated(SurfaceHolder surfaceHolder)
surfaceHolder
- The SurfaceHolder whose surface is being created.public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
holder
- The SurfaceHolder whose surface has changed.public void surfaceDestroyed(SurfaceHolder holder)
holder
- The SurfaceHolder whose surface is being destroyed.public void onPause()
onPause()
method to store the state of the
camera preview display before the application is sent to the background.
The stored state can then be restored with a corresponding call to onResume()
made from the activity's onResume()
method.public void onResume()
public WZSize getScreenSize()
public void registerFrameRenderer(WZRenderAPI.VideoFrameRenderer frameRenderer)
WZRenderAPI.VideoFrameRenderer
interface
that can be used to render additional content, such as a logo, to the camera preview displayframeRenderer
- An instance of a WZRenderAPI.VideoFrameRenderer
implementationpublic void unregisterFrameRenderer(WZRenderAPI.VideoFrameRenderer frameRenderer)
frameRenderer
- A previously registered instance of a WZRenderAPI.VideoFrameRenderer
implementationpublic void registerFrameListener(WZRenderAPI.VideoFrameListener frameListener)
WZRenderAPI.VideoFrameListener
interface
that can be used to capture content from the camera preview displayframeListener
- An instance of a WZRenderAPI.VideoFrameListener
implementationpublic void unregisterFrameListener(WZRenderAPI.VideoFrameListener frameListener)
frameListener
- A previously registered instance of a WZRenderAPI.VideoFrameListener
implementation© 2016 Wowza Media Systems, LLC. All rights reserved. Terms | Privacy | Trademarks | Legal