Advanced Usage

Improve Playback

On HLS Live streaming or mp4 streaming, to improve performance, we recommend to tell p2p engine the duration from the playback time to the end of the buffered interval. In order to do so, you need to use callback setPlayerInteractor .

import com.p2p.core.p2p.PlayerInteractor;

P2pEngine.getInstance().setPlayerInteractor(new PlayerInteractor() {
    @Override
    public long onBufferedDuration() {
        // Exoplayer in milliseconds
        return player.getBufferedPosition() - player.getCurrentPosition();
    }
});

Dynamic Url Issue

The channelId is an identifier used by our backend to match peers that are watching the same content. It is an optional parameter, and by default, we generate channelId from the content URL by removing any query parameters and protocol from it. Some urls play the same live/vod but have different paths on them. For example, example.com/live/channel-live1/playlist.m3u8 and example.com/live/channel-live2/playlist.m3u8. In this case, you can format a common channelId for them.

// Set channelIdPrefix in p2pConfig before setting channelId! Connectivity with other platform should have the same channelIdPrefix.
P2pConfig config = new P2pConfig.Builder() 
    .channelIdPrefix(YOUR_UNIQUE_ID)                           
    .build();  
P2pEngine.init(getApplicationContext(), token, config);

Interconnect with other platform should ensure that both have the same channelIdPrefix and channelId.

HLS & DASH & MP4

File download

Dynamic Media File Path Issue

Like dynamic m3u8/mpd path issue, you should format a common segmentId for the same media file. You can override the segment ID like this:

Setup HTTP headers

Some HTTP requests need to add header information such as User-Agent for Anti-Leech or statistical requirements. It can be set via setHttpHeaders :

P2P First Strategy

Since it takes time to establish a P2P connection, the first few pieces are downloaded using HTTP by default. Giving the peers extra time to download initial segments will increase the p2p ratio. However, it may cause delay. It is recommended to turn on the hot channel.

Last updated

Was this helpful?