Quick Start
Import P2pEngine
We recommend calling P2pEngine.initEngine in the instance of the Application class right after the application is created
import com.p2p.sdk.P2pEngine;
Initialize P2pEngine
public class MyApplication extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
P2pEngine.init(this, YOUR_TOKEN, null);
}
}
YOUR_TOKEN is your Customer ID
Playback
When initializing a media player (or any other video player, ExoPlayer is highly recommended) instance, before passing it a URL, pass that URL through P2P Engine
private void onPlay(){
String parsedUrl = P2pEngine.getInstance().parseStreamUrl("https://link_stream");
mediaPlayer.play(parsedUrl);
}
File Download
Pass the file url to start the download, and then get the file path through the callback function after the download is completed.
try {
DownloadInfo info = P2pEngine.getInstance().downloadFile(url);
if (info.isCached()) {
// already downloaded
File file = info.getCacheFile();
}
} catch (Exception e) {
// fallback
}
P2pEngine.getInstance().registerFileDownloadListener(new FileDownloadListener() {
@Override
public void onDownloadFailed(Throwable e) {
// fallback
}
@Override
public void onDownloadFinished(File cacheFile, String url) {
// get downloaded file here
}
@Override
public void onCacheAvailable(File cacheFile, String url, int percentsAvailable) {
// show progress to user
}
});
Resolve OOM Issue in Android set-top box
You can resolve OOM by increasing heap size, add the attribute below in app/src/main/AndroidManifest.xml:
<application
...
android:largeHeap=“true”
...
/>
Last updated
Was this helpful?