On this page

IpcPlayer

Requires:
@ray-js/ray≥0.6.9

Description

Real-time video playback component. A native component with separate-layer rendering; be aware of the limitations on native components.

Props

PropertyTypeRequiredDefaultDescriptionSince
deviceIdstringYes""Device ID; the component's unique identifier; required-
autoplaybooleanNofalseAutoplay-
mutedbooleanNo-Whether to mute-
clarity"ss" | "normal" | "hd" | "ud" | "ssp" | "auto" | "audio"NonormalQuality: ss (data saver), normal (SD), hd (HD), ud (UHD), ssp (extra HD), auto (auto), audio (audio mode)-
soundMode"speaker" | "ear"NospeakerAudio output: speaker (loudspeaker), ear (earpiece)-
orientation"vertical" | "horizontal"NoverticalScreen orientation: vertical (portrait), horizontal (landscape)-
objectFit"contain" | "fillCrop"NocontainFill mode: contain (fit long edge), fillCrop (cover and crop)-
autoPauseIfNavigatebooleanNotrueWhether to auto-pause real-time audio/video when navigating to another page within this mini program-
autoPauseIfOpenNativebooleanNotrueWhether to auto-pause real-time audio/video when navigating to other native pages in the app-
rotateZnumberNo0Camera rotation angle, 0–360-
scalablebooleanNotrueWhether zoom is currently enabled-
scaleMultiplenumberNo0Zoom ratio; takes effect only when scalable is true-
ptzControllablebooleanNotrueWhether to enable cloud platform control for the video area-
borderWidthnumber | stringNo0Border width, in px-
borderStyle"solid" | "dashed"NosolidBorder style: solid, dashed-
borderColorstringNo#ffffffBorder color, hex-
borderRadiusnumber | stringNo0Border radius, in px-
backgroundColorstringNo#ffffffBackground color, hex-
No-Additional properties@ray-js/ray 1.7.79
No-Fires when the connection state changes; use onConnectChange-
No-Fires when the preview state changes; use onPreviewChange-
No-Fires when the device online status changes; use onOnlineChange-
No-Fires when initialization completes; use onInitDone-
No-Fires when the video zoom ratio changes; use onZoomChange-
No-Fires when the video is tapped; use onVideoTap-
No-Fires when the connection state changes; state = 0 indicates connection successful-
No-Fires when the preview state changes; state = 1 indicates preview started successfully, 0 indicates preview ended successfully-
No-Fires when the IPC device online status changes-
No-Triggered when initialization completes-
No-Fires when the video zoom ratio and current zoom factor change-
No-Fires when the video is tapped-
No-Fires when the state is abnormal-
No-Disconnected (⚠️ Not delivered on Android; disconnection is reflected via onConnectChange with state < 0)-
No-Preview failed (fires when P2P sessionStatus < 0; shared by normal and multi-lens preview)IPCKit 6.1.4
No-Weak network notificationIPCKit 6.1.4
No-Fires when the overlay component is created successfullyIPCKit 6.2.3
No-Fires when a video index is selectedIPCKit 7.3.3
No-Fires when the layout state changesIPCKit 7.3.3
No-Fires when the locator positionsIPCKit 7.3.3
No-Fires when a swipe gesture on the player is reported and PTZ rotation is requiredIPCKit 7.3.3
updateLayoutunknownNo-Used for cross-layer components to notify the container layer to update styles-

Referenced Types

interfaceIpcPlayerSessionDidDisconnectedEvent
export interface IpcPlayerSessionDidDisconnectedEvent extends BaseEvent {
  /** 事件类型 */
  type: 'sessionDidDisconnected';
}
interfaceIpcPlayerCreateViewSuccessEvent
export interface IpcPlayerCreateViewSuccessEvent extends BaseEvent {
  /** 事件类型 */
  type: 'createViewSuccess';
}
interfaceBaseEvent
PropertyTypeRequiredDescription
typestringYesEvent type
timeStampnumberYesTime in milliseconds since the page opened
YesSource component of the event
YesCollection of property values for the current component
markanyNoEvent mark data
interfaceTarget
PropertyTypeRequiredDescription
idstringYesid of the event source component
YesCollection of custom attributes from the `dataset` on the event source component

Valid Values

clarity
ValueDescriptionSince
ssData-saving quality-
normalStandard-definition quality-
hdHigh-definition quality-
udUltra-high-definition quality-
sspSuper-ultra-high-definition quality-
autoAutomatically select video quality-
audioAudio mode-
soundMode
ValueDescriptionSince
speakerOutput audio through the speaker-
earOutput audio through the earpiece-
orientation
ValueDescriptionSince
verticalVertical-
horizontalHorizontal-
objectFit
ValueDescriptionSince
containPreserve the aspect ratio and fit the longer side to display the entire image-
fillCropPreserve the aspect ratio and fill the container, cropping any overflow-
borderStyle
ValueDescriptionSince
solidSolid border-
dashedDashed border-

Examples

Basic usage

import React from 'react';
import { IpcPlayer, View, Text } from '@ray-js/ray';

export default function () {
  return (
    <View style={{ padding: '20px' }}>
      <Text style={{ marginBottom: '10px' }}>IPC Live Video</Text>
      <IpcPlayer
        deviceId="your-device-id"
        autoplay
        style={{ width: '100%', height: '300px' }}
        onInitDone={(e) => {
          console.log('Initialization complete, max zoom scale:', e.detail.maxScaleMultiple);
        }}
        onError={(e) => {
          console.log('Error:', e.detail);
        }}
      />
    </View>
  );
}

IPC playback control

import React, { useState } from 'react';
import { IpcPlayer, View, Text, Button, createIpcPlayerContext } from '@ray-js/ray';

export default function () {
  const [isOnline, setIsOnline] = useState(false);
  const [connectState, setConnectState] = useState(-1);
  const [previewState, setPreviewState] = useState(-1);
  const playerId = 'myIpcPlayer';

  const handleStartPreview = () => {
    const ctx = createIpcPlayerContext(playerId);
    ctx.startPreview();
  };

  const handleStopPreview = () => {
    const ctx = createIpcPlayerContext(playerId);
    ctx.stopPreview();
  };

  return (
    <View style={{ padding: '20px' }}>
      <IpcPlayer
        id={playerId}
        deviceId="your-device-id"
        autoplay={false}
        muted={false}
        clarity="hd"
        soundMode="speaker"
        orientation="vertical"
        objectFit="contain"
        scalable
        ptzControllable
        borderRadius={8}
        style={{ width: '100%', height: '300px' }}
        onConnectChange={(e) => {
          console.log('Connection status changed:', e.detail.state);
          setConnectState(e.detail.state);
        }}
        onPreviewChange={(e) => {
          console.log('Preview status changed:', e.detail.state);
          setPreviewState(e.detail.state);
        }}
        onOnlineChange={(e) => {
          console.log('Online status changed:', e.detail.online);
          setIsOnline(e.detail.online);
        }}
        onZoomChange={(e) => {
          if ('zoomLevel' in e.detail) {
            console.log('Zoom changed:', e.detail.zoomLevel);
          }
        }}
        onVideoTap={() => {
          console.log('Video tapped');
        }}
        onError={(e) => {
          console.log('Error:', e.detail);
        }}
      />
      <View style={{ marginTop: '10px' }}>
        <Text>Device online: {isOnline ? 'Yes' : 'No'}</Text>
        <Text>Connection status: {connectState === 0 ? 'Connected' : 'Not connected'}</Text>
        <Text>Preview status: {previewState === 1 ? 'Previewing' : 'Not previewing'}</Text>
      </View>
      <View style={{ marginTop: '10px', display: 'flex', flexDirection: 'row', gap: '8px' }}>
        <Button size="mini" onClick={handleStartPreview}>Start preview</Button>
        <Button size="mini" onClick={handleStopPreview}>Stop preview</Button>
      </View>
    </View>
  );
}

Error Codes

ValueDescription
-1000Other unknown exception
-1001connect failed
-1002Start preview failed
-1003Stop preview failed
-1004Set mute failed
-1005Set clarity failed
-1006Screenshot failed
-1007Invalid property
-1008Invalid parameter
-1009disconnect failed
-1010Network unavailable
-1011Device offline
-1012Device removed
-1013startTalk fail
-1014StopTalk fail
-1015StartRecord fail
-1016StopRecord fail
-1017IsTalkBacking fail
-1018SetAvailableRockerDirections fail
-1019IsPTZControllable fail
-1020SetTrackingStatus fail
-1021GetVideoInfo fail

Related API: createIpcPlayerContext. This is a native component based on off-screen rendering. Please note the native component usage restrictions.

FAQ

  1. ipc-player default width is 300px and height is 225px. You can set the width and height via tyss.
  2. Not supported in the Tuya MiniApp IDE.
  3. For related principles, refer to Native components based on off-screen rendering.
  4. Please note the native component usage restrictions.