All Products
Search
Document Center

ApsaraVideo VOD:Basic features

Last Updated:Mar 22, 2024

This topic describes how to create a player instance and use basic features of ApsaraVideo Player SDK for Android, such as setting the volume, performing video seeking, monitoring playback status, enabling loop playback, configuring the playback speed, and switching audio tracks.

Create a player

This section describes how to use ApsaraVideo Player SDK for Android to play videos. Manual playback and autoplay are supported.

  1. Create a player.

    Call the AliPlayerFactory class to create an AliPlayer object.

    Note

    ApsaraVideo VOD supports the playback quality monitoring, single-point tracing, and statistical analysis features based on the event tracking logs. You can use the playback quality monitoring feature to query statistics about overall playback quality and use the single-point tracing feature to locate the specific user or device, analyze the playback behavior, and identify the error in an efficient manner. For more information, see Playback quality monitoring, Single-point tracing, and Statistical analysis.

    You can configure the setTraceId parameter to use the features. The following content describes the configurations:

    • If you leave the setTraceId parameter empty, the event tracking logs are automatically uploaded. You can use only the playback quality monitoring and statistical analysis features. By default, this parameter is left empty.

    • If you specify the unique identifier of the device or the user for the setTraceId parameter, the event tracking logs are automatically uploaded. You can use the playback quality monitoring, single-point tracing, and statistical analysis features. For example, you can specify the user ID or device ID such as the International Mobile Equipment Identity (IMEI) or the Identifier for Advertisers (IDFA) for this parameter.

    • If you specify DisableAnalytics for the setTraceId parameter, the event tracking logs are not uploaded. You cannot use the playback quality monitoring, single-point tracing, or statistical analysis feature.

    // Create a player.
    AliPlayer aliPlayer = AliPlayerFactory.createAliPlayer(context);
    // We recommend that you specify the traceId parameter.
    aliPlayer.setTraceId("traceId");  

    Note

    The event tracking logs are uploaded to the points of presence (POPs) in the China (Shanghai) region. POPs in the Singapore region will be supported in the future.

  2. Configure listeners.

    You can configure multiple listeners for your player.

    • You must configure OnPreparedListener. This way, you can call aliPlayer.start() in the OnPreparedListener callback to start manual playback.

    • We recommend that you configure OnErrorListener, OnCompletionListener, OnLoadingStatusListener, and OnInfoListener.

    aliPlayer.setOnErrorListener(new IPlayer.OnErrorListener() {
        // If an error occurs when you use the player, this callback is returned. 
    
        @Override
        public void onError(ErrorInfo errorInfo) {
            ErrorCode errorCode = errorInfo.getCode() // The error code. 
            String errorMsg =errorInfo.getMsg(); // The error message. 
            // errorExtra indicates the supplementary error message. The value is a JSON string. The following sample code shows the structure of the errorExtra parameter. The value of the ModuleCode field is not the same as the value of the errorCode parameter.
            //{ "Url": "xxx",
       		//	"Module": "NetWork",
        	//	"ModuleCode": "-377",
       		//  "ModuleMessage": "Redirect to a url that is not a media"}
            String errorExtra= errorInfo.getExtra();         
            // Stop the player if an error occurs. 
            aliPlayer.stop();
        }
    });
    aliPlayer.setOnPreparedListener(new IPlayer.OnPreparedListener() {
        // The player starts to read and parse data after you call the aliPlayer.prepare() method. This callback is returned after data is parsed. 
    
        @Override
        public void onPrepared() {
            // Call the start method to start the playback. 
            aliPlayer.start();
        }
    });
    aliPlayer.setOnCompletionListener(new IPlayer.OnCompletionListener() {
        // This callback is returned after the playback ends. 
        @Override
        public void onCompletion() {
            // Call the stop method to stop the playback. 
            aliPlayer.stop();
        }
    });
    aliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
        // The information about the player, such as the current playback progress and buffer position. 
        @Override
        public void onInfo(InfoBean infoBean) {
            InfoCode code = infoBean.getCode(); // The information code. 
            String msg = infoBean.getExtraMsg(); // The information content. 
            long value = infoBean.getExtraValue(); // The information value. 
    
            // Current progress: InfoCode.CurrentPosition
            // Current buffer position: InfoCode.BufferedPosition
        }
    });
    aliPlayer.setOnLoadingStatusListener(new IPlayer.OnLoadingStatusListener() {
        // The loading status. If the network is unstable, this method is called to display the loading status. 
    
        @Override
        public void onLoadingBegin() {
            // The loading starts. In this case, you cannot play video and audio streams. 
            // The loading circle is displayed. 
        }
    
        @Override
        public void onLoadingProgress(int percent, float netSpeed) {
            // The loading progress. The loading percentage and network speed are displayed. 
        }
    
        @Override
        public void onLoadingEnd() {
            // The loading ends. In this case, you can play video and audio streams. 
            // The loading circle is hidden. 
        }
    });
  3. Configure a playback source.

    • ApsaraVideo Player SDK for Android supports video-on-demand (VOD) playback based on UrlSource, VidAuth, and VidSts. Encrypted VOD playback is also supported. We recommend that you play videos based on VidAuth in ApsaraVideo VOD.

    • ApsaraVideo Player SDK for Android supports UrlSource-based and encrypted live streaming.

    Note
    • UrlSource is used for URL-based playback, and VidSts and VidAuth are used for Vid-based playback.

    • For more information about regions, see Region IDs of ApsaraVideo VOD.

    VOD playback

    UrlSource-based playback

    If you play an on-demand video based on UrlSource, you must set the setUrl parameter to the playback URL of the video.

    • You can call the GetPlayInfo operation to obtain playback URLs in ApsaraVideo VOD. We recommend that you integrate ApsaraVideo VOD SDKs to obtain media playback URLs in ApsaraVideo VOD. This frees you from complex signature calculations. For more information about the GetPlayInfo operation, visit OpenAPI Explorer.

    • Make sure that you are authorized to call API operations to obtain the full path of the local file if you want to play a local video. Example: /sdcard/xxx/xxx/xxx.mp4 or content://xxx/xxx/xx.mp4.

     UrlSource urlSource = new UrlSource();
            urlSource.setUri("Playback URL");// Required. The playback URL of the video. The URL can be generated by ApsaraVideo VOD or a third-party service. You can also use the URL of a local video. 
            aliPlayer.setDataSource(urlSource);

    (Recommended) VidAuth-based playback

    If you play an on-demand video based on VidAuth, you must set the vid parameter to the ID of the media file and set the playAuth parameter to the playback credential.

    • After you upload an audio or video file, you can log on to the ApsaraVideo VOD console and choose Media Files > Audio/Video to view the ID of the audio or video file. Alternatively, you can call the SearchMedia operation provided by the ApsaraVideo VOD SDK to obtain the ID.

    • You can call the GetVideoPlayAuth operation to obtain the playback credential. We recommend that you integrate ApsaraVideo VOD SDKs to obtain credentials for media playback in ApsaraVideo VOD. This frees you from complex signature calculations. For more information about the GetVideoPlayAuth operation, visit OpenAPI Explorer.

    We recommend that you use VidAuth for video playback in ApsaraVideo VOD. Compared with STS-based playback, VidAuth-based playback is easier to use and more secure. For more information about the differences between the two playback methods, see Comparison between credentials and STS.

    VidAuth vidAuth = new VidAuth();
            vidAuth.setVid("Vid");// Required. The video ID. 
            vidAuth.setPlayAuth("yourPlayAuth"); // Required. The playback credential. To obtain the playback credential, call the GetVideoPlayAuth operation in ApsaraVideo VOD. 
            vidAuth.setRegion("Access region"); // This parameter is deprecated in ApsaraVideo Player SDK V5.5.5.0 or later. If you use ApsaraVideo Player SDK V5.5.5.0 or later, the player automatically parses the region information. If you use ApsaraVideo Player SDK V5.5.5.0 or earlier, this parameter is required. Specify the ID of the region in which ApsaraVideo VOD is activated for this parameter. Default value: cn-shanghai. 
            // vidAuth.setAuthTimeout(3600);// The validity period of the playback URL. Unit: seconds. Default value: 3600. This settings overwrites the validity period that you configured in the ApsaraVideo VOD console. If you leave this parameter empty, the default value 3600 is used. The validity period must be longer than the actual duration of the video. Otherwise, the playback URL expires before the playback is complete. 
            aliPlayer.setDataSource(vidAuth);

    VidSts-based playback

    If you play an on-demand video based on VidSts, a temporary STS token is used instead of a playback credential. In this case, you must obtain an STS token and AccessKey pair (AccessKey ID and AccessKey secret) before you play videos on demand. For more information about how to obtain an STS token, see Create a RAM role and grant temporary access permissions to the role by using STS.

    VidSts vidSts = new VidSts();
            vidSts.setVid("Vid"); // Required. The video ID. 
            vidSts.setAccessKeyId("<yourAccessKeyId>"); // Required. The AccessKey ID that is issued together with the STS token. To generate the AccessKey ID, call the AssumeRole operation in STS. 
            vidSts.setAccessKeySecret("<yourAccessKeySecret>");// Required. The AccessKey secret that is issued together with the STS token. To generate the AccessKey secret, call the AssumeRole operation in STS. 
            vidSts.setSecurityToken("<yourSecurityToken>");// Required. The STS token. To generate an STS token, call the AssumeRole operation in STS. 
            vidSts.setRegion("Access region"); // Required. The ID of the region in which ApsaraVideo VOD is activated. Default value: cn-shanghai. 
            // vidSts.setAuthTimeout(3600);// The validity period of the playback URL. Unit: seconds. Default value: 3600. This settings overwrites the validity period that you configured in the ApsaraVideo VOD console. If you leave this parameter empty, the default value 3600 is used. The validity period must be longer than the actual duration of the video. Otherwise, the playback URL expires before the playback is complete. 
            aliPlayer.setDataSource(vidSts);

    Encrypted playback

    ApsaraVideo VOD supports HTTP-Live-Streaming (HLS) encryption, Alibaba Cloud proprietary cryptography, and digital rights management (DRM) encryption. For more information, see Play an encrypted video.

    Live streaming

    UrlSource-based live streaming

    If you play a live stream based on UrlSource, you must set the setUrl parameter to the streaming URL of the video. The streaming URL is generated by ApsaraVideo Live or a third-party service.

    You can generate a streaming URL for a live stream by using the URL generator in the ApsaraVideo Live console. For more information, see URL generator.

    UrlSource urlSource = new UrlSource();
            urlSource.setUri("Streaming URL");// The streaming URL. The URL is generated by ApsaraVideo Live or a third-party service. 
            aliPlayer.setDataSource(urlSource);

    DRM-encrypted live streaming

    For more information about DRM-encrypted live streaming, see Use ApsaraVideo Player SDK for Web.

  4. Configure the view.

    You can call the SurfaceView or TextureView method to configure the view.

    • The following sample code provides an example on how to use SurfaceView to configure the view:

      SurfaceView surfaceView = findViewById(R.id.surface_view);
      surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
          @Override
          public void surfaceCreated(SurfaceHolder holder) {
              aliPlayer.setSurface(holder.getSurface());
          }
      
          @Override
          public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
              aliPlayer.surfaceChanged();
          }
      
          @Override
          public void surfaceDestroyed(SurfaceHolder holder) {
              aliPlayer.setSurface(null);
          }
      });
    • The following sample code provides an example on how to use TextureView to configure the view:

      TextureView textureView = findViewById(R.id.texture_view);
      textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
          @Override
          public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
              aliPlayer.setSurface(new Surface(surface));
          }
      
          @Override
          public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
              aliPlayer.surfaceChanged();
          }
      
          @Override
          public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
              aliPlayer.setSurface(null);
              return false;
          }
      
          @Override
          public void onSurfaceTextureUpdated(SurfaceTexture surface) {
      
          }
      });
  5. Optional. Enable the autoplay feature. By default, the autoplay feature is disabled.

    aliPlayer.setAutoPlay(true);
  6. Prepare the player.

    Call the aliPlayer.prepare() method to read and parse data.

    aliPlayer.prepare();
  7. Start the playback.

    • If the autoplay feature is not enabled, you must call the aliPlayer.start() method in the OnPrepared callback to start the playback.

    • If the autoplay feature is enabled, you do not need to call the aliPlayer.start() method. After the data is parsed, the video is automatically played.

    aliPlayer.start();// After the playback starts, you can call the pause() method to pause the playback.

Manage playback

ApsaraVideo Player SDK for Android allows you to manage media playback. For example, you can start, pause, or stop the playback, or start the playback from a specific point in time.

Start the playback

You can call the start method to start the playback. Sample code:

aliyunVodPlayer.start();

Play a video from a specified point in time

You can call the seekTo method to play a video from a specified point in time. This feature is used when the user drags the slider on the progress bar or the video is resumed from a specific point in time. Sample code:

// The position parameter specifies the point in time when playback starts. Unit: milliseconds. 
aliyunVodPlayer.seekTo(long position);

Pause the playback

You can call the pause method to pause the playback. Sample code:

aliyunVodPlayer.pause();

Stop the playback

You can call the stop method to stop the playback. Sample code:

aliyunVodPlayer.stop();

Set the video display mode

ApsaraVideo Player SDK for Android allows you to configure display settings for playback. For example, you can specify how video images are scaled, rotated, or mirrored.

Scaling

You can call setScaleMode to scale in or scale out a video without changing the original aspect ratio, or stretch a video. Sample code:

// Scale in the video to fit the view. The aspect ratio of the video is maintained.
aliyunVodPlayer.setScaleMode(ScaleMode.SCALE_ASPECT_FIT);
// Scale out the video to fill the view. The aspect ratio of the video is maintained.
aliyunVodPlayer.setScaleMode(ScaleMode.SCALE_ASPECT_FILL);
// Stretch the video to fill the view. The aspect ratio of the video is not maintained. If the aspect ratios of the video and the view are different, image distortion may occur.
aliyunVodPlayer.setScaleMode(ScaleMode.SCALE_TO_FILL);

Rotating

You can call setRotateMode to specify a rotation angle for video images. You can query the rotation angle after it is set. Sample code:

// Set the rotation angle to 0° in the clockwise direction.
aliyunVodPlayer.setRotateMode(RotateMode.ROTATE_0);
// Set the rotation angle to 90° in the clockwise direction.
aliyunVodPlayer.setRotateMode(RotateMode.ROTATE_90);
// Set the rotation angle to 180° in the clockwise direction.
aliyunVodPlayer.setRotateMode(RotateMode.ROTATE_180);
// Set the rotation angle to 270° in the clockwise direction.
aliyunVodPlayer.setRotateMode(RotateMode.ROTATE_270);
// Query the rotation angle.
aliyunVodPlayer.getRotateMode();

Mirroring

You can call setMirrorMode to specify a mirroring mode. Horizontal mirroring, vertical mirroring, and no mirroring are supported. Sample code:

// Specify no mirroring for the video images.
aliyunVodPlayer.setMirrorMode(MirrorMode.MIRROR_MODE_NONE);
// Specify horizontal mirroring for the video images.
aliyunVodPlayer.setMirrorMode(MirrorMode.MIRROR_MODE_HORIZONTAL);
// Specify vertical mirroring for the video images.
aliyunVodPlayer.setMirrorMode(MirrorMode.MIRROR_MODE_VERTICAL);

Obtain the playback information

ApsaraVideo Player SDK for Android allows you to obtain playback information, such as the current playback progress, playback duration, and buffering progress.

Obtain the playback progress

You can call getExtraValue in the onInfo callback to obtain the current playback position. Sample code:

mAliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
    @Override
    public void onInfo(InfoBean infoBean) {
        if(infoBean.getCode() == InfoCode.CurrentPosition){
            // The extraValue parameter indicates the current playback position. Unit: milliseconds.
            long extraValue = infoBean.getExtraValue();
        }
    }
});

Obtain the playback duration

You can query the total duration of a video. The video duration can be obtained only after the video is loaded. You can call getDuration after the onPrepared event is invoked to query the video duration. Sample code:

long duration = mAliPlayer.getDuration();

Obtain the buffer position

You can call getExtraValue in the onInfo callback to query the current buffering progress. Sample code:

mAliPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
    @Override
    public void onInfo(InfoBean infoBean) {
        if(infoBean.getCode() == InfoCode.BufferedPosition){
            // The extraValue parameter indicates the buffering progress. Unit: milliseconds.
            long extraValue = infoBean.getExtraValue();
        }
    }
});

Obtain the rendering frame rate, audio and video bitrate, and network downlink bitrate in real time

Sample code:

// Obtain the current frame rate for video rendering. The returned data is of the FLOAT data type. 
mAliPlayer.getOption(IPlayer.Option.RenderFPS);
// Obtain the current video bitrate. The returned data is of the FLOAT data type. Unit: bit/s. 
mAliPlayer.getOption(IPlayer.Option.VideoBitrate);
// Obtain the current audio bitrate. The returned data is of the FLOAT data type. Unit: bit/s. 
mAliPlayer.getOption(IPlayer.Option.AudioBitrate);
// Obtain the current network downlink bitrate. The returned data is of the FLOAT data type. Unit: bit/s. 
mAliPlayer.getOption(IPlayer.Option.DownloadBitrate);

Obtain the player status

You can listen to the player status in the onStateChanged callback. Sample code:

mAliPlayer.setOnStateChangedListener(new IPlayer.OnStateChangedListener() {
    @Override
    public void onStateChanged(int newState) {
        /*
          int idle = 0;
          int initalized = 1;
          int prepared = 2;
          int started = 3;
          int paused = 4;
          int stopped = 5;
          int completion = 6;
          int error = 7;
      */
    }
});

Specify the volume

You can set the mute mode and the volume.

Change the volume

You can change the volume of a video to up to twice the original volume. However, noise may occur if you set the volume to a value higher than 1. Call setVolume to change the volume. You can also obtain the current volume. Sample code:

// Set the volume to a real number from 0 to 2. 
aliyunVodPlayer.setVolume(1f);
// Obtain the volume. 
aliyunVodPlayer.getVolume();

Mute the player

Call setMute to mute a video that is being played. Sample code:

aliyunVodPlayer.setMute(true);

Configure the playback speed

ApsaraVideo Player SDK for Android allows you to call setSpeed to change the playback speed. Playback speeds ranging from 0.5x to 5x are supported. The audio pitch remains unchanged at different speeds. Sample code:

// Playback speeds ranging from 0.5x to 5x are supported. Common playback speeds are multiples of 0.5x, such as 0.5x, 1x, and 1.5x.
aliyunVodPlayer.setSpeed(1.0f);

Configure multi-definition playback

Configure UrlSource-based live streaming

    Note
    • You can play live streams based on URLs in ApsaraVideo Live or URLs of the transcoded live streams. Default transcoding and custom transcoding are supported. For more information about how to transcode live streams, see Transcoding management. For more information about how to obtain streaming URLs, see Ingest and streaming URLs.

    • You can switch between live streams in different definitions. Only Real-Time Messaging Protocol (RTMP) and Flash Video (FLV) streams are supported.

    • You must set the group of pictures (GOP) size to 2 seconds and the timestamp to the time when the source video is pushed.

    • If you change the streaming URL to a URL that does not meet the preceding requirements, the switching fails.

Switch between definitions

Call the switchStream method to switch between live streams in different definitions. Specify the URL of the live stream that you want to play.

mAliPlayer.switchStream(newUrl);

Set the callbacks for definition switching

Set the callbacks for the successful and failed definition switching.

mAliPlayer.setOnStreamSwitchedListener(new IPlayer.OnStreamSwitchedListener() {
    @Override
    public void onSwitchedSuccess(String url) {
        Log.i("SwitchStream", "switch success, url = " + url);
    }

    @Override
    public void onSwitchedFail(String url, ErrorInfo errorInfo) {
        Log.i("SwitchStream", "switch failed, url = " + url + ", error=" + errorInfo.getMsg());
    }
});

Configure VidAuth or VidSts-based playback

If you use VidAuth or VidSts to play on-demand videos, no additional settings are required. ApsaraVideo Player SDK for Android automatically obtains video definitions from ApsaraVideo VOD.

Obtain video definitions

After the video is loaded, you can obtain the definitions of the video.

// Obtain information about all streams of the video.
List<TrackInfo> trackInfos = mAliPlayer.getMediaInfo().getTrackInfos();
// Traverse all streams to obtain the video definitions.
for (TrackInfo trackInfo : trackInfos) {
     if(trackInfo.getType() == TrackInfo.Type.TYPE_VOD){
             // Obtain the video definition.
        String vodDefinition = trackInfo.getVodDefinition();
     }
}

Switch between definitions

You can call selectTrack and specify the index that corresponds to the definition to which you want to switch. You can obtain the index from the TrackInfo parameter.

mAliPlayer.selectTrack(index);

Set the callbacks for definition switching

Set the callbacks for the successful and failed definition switching.

mAliPlayer.setOnTrackChangedListener(new IPlayer.OnTrackChangedListener() {
    @Override
    public void onChangedSuccess(TrackInfo trackInfo) { }

    @Override
    public void onChangedFail(TrackInfo trackInfo, ErrorInfo errorInfo) { }
});

Enable loop playback

ApsaraVideo Player SDK for Android supports loop playback. Call setLoop to enable loop playback. The loop playback feature allows you to play a video again from the beginning after the video playback ends. Sample code:

aliyunVodPlayer.setLoop(true);

The onInfo callback is returned when loop playback starts. Sample code:

aliyunVodPlayer.setOnInfoListener(new IPlayer.OnInfoListener() {
    @Override
    public void onInfo(InfoBean infoBean) {
        if (infoBean.getCode() == InfoCode.LoopingStart){
            // Listen to the start of loop playback. 
        }
    }
});

Switch audio tracks

ApsaraVideo Player SDK for Android supports audio track switching. This allows you to switch audio tracks in different languages during video playback.

Usage notes

You can switch audio tracks in streams that are not used for list playback such as MP4 streams, single-bitrate mixed HLS streams, audio tracks in single-bitrate HLS streams, and substreams in multi-bitrate mixed HLS streams. The following table describes different types of video streams.

Type

Video stream suffix

Bitrate quantity

M3U8 file quantity

Substream type

Description

Non-list stream (such as MP4 stream)

.mp4

1

-

A stream that contains a video track, multiple audio tracks, and multiple subtitle tracks.

You can switch between audio tracks.

Single-bitrate mixed HLS stream

.m3u8

1

1

A stream that contains a video track, multiple audio tracks, and multiple subtitle tracks.

You can switch between audio tracks.

Single-bitrate HLS stream

.m3u8

1

n

An M3U8 stream that contains only video tracks, audio tracks, or subtitle tracks.

You can switch between audio tracks.

Multi-bitrate mixed HLS stream

.m3u8

n

n

An M3U8 stream that contains a video track, multiple audio tracks, and multiple subtitle tracks. The bitrate of the substreams are different.

You can switch between different substreams. You cannot switch between the audio tracks of a substream.

Example

  1. Configure callbacks.

    mAliyunVodPlayer.setOnSubTrackReadyListener(new IPlayer.OnSubTrackReadyListener() {
        @Override
        // Configure the onSubTrackReady callback. In most cases, the onSubTrackReady callback is fired before the prepare callback. 
        public void onSubTrackReady(MediaInfo mediaInfo) {
            if (mPlayerTrackFragment != null) {
                //mPlayerTrackFragment.showMediaInfo();
                // Call the getSubMediaInfo operation and obtain MediaInfo from the response. You must call the getSubMediaInfo operation after the onSubTrackReady callback is fired. Otherwise, an empty string is returned. 
                MediaInfo subMediaInfo = mAliyunVodPlayer.getSubMediaInfo();
                TrackInfos = subMediaInfo.getTrackInfos();
                // Find the track to which you want to switch.
                myTrack = myfunc(TrackInfos)
            }
        }
    });
  2. Switch to the desired track.

    index = myTrack.getIndex();
    mAliyunVodPlayer.selectTrack(index);

Obtain SDK logs

SDK logs are generated when you use ApsaraVideo Player SDK. The logs contain detailed information such as request status, invocation results, and permission application results. You can debug code and troubleshoot problems by viewing the SDK logs to facilitate development. You can use one of the following methods to obtain SDK logs.

Method 1: Use the console of your development tool

This method captures logs on your local device. It is suitable for scenarios where you can reliably reproduce the error on your device.

  1. Enable the logging feature and set the log level.

    // The logs are stored under com.cicada.player.utils.
    // Enable the logging feature.
    Logger.getInstance(context).enableConsoleLog(true);
    // Set the log level. Default value: AF_LOG_LEVEL_INFO. To troubleshoot problems, set this parameter to AF_LOG_LEVEL_TRACE.
    Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_INFO);
  2. Collect logs.

    Reproduce the error and obtain the error log in the console of your development tool such as Logcat.

Method 2: Listen to the log export of the player SDK

This method uses the LogCallback method. It is suitable for scenarios where the error occurs on the client side but you cannot reliably reproduce the error and capture logs on your device. You can call LogCallback to listen to the log export of ApsaraVideo Player SDK and automatically export error logs to the log channel of your application.

  1. Enable the logging feature and set the log level.

    // The logs are stored under com.cicada.player.utils.
    // Set the log level. Default value: AF_LOG_LEVEL_INFO. To troubleshoot problems, set this parameter to AF_LOG_LEVEL_TRACE.
    Logger.getInstance(context).setLogLevel(Logger.LogLevel.AF_LOG_LEVEL_INFO);
    Logger.getInstance(mContext).setLogCallback(newLogger.OnLogCallback(){
            @Override
            public void onLog(Logger.LogLevel logLevel,Strings){
                // The logs.
            }
    });
  2. Collect logs.

    After an error occurs, the system automatically exports the error log to the log channel of your application.

References