check buffering events
This commit is contained in:
parent
33094f8c88
commit
e829d5483a
3 changed files with 83 additions and 0 deletions
59
app/src/main/java/io/lbry/browser/tasks/BufferEventTask.java
Normal file
59
app/src/main/java/io/lbry/browser/tasks/BufferEventTask.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class BufferEventTask extends AsyncTask<Void, Void, Void> {
|
||||
private static final String TAG = "LbryBufferEvent";
|
||||
private static final String ENDPOINT = "https://api.lbry.tv/api/v1/metric/ui";
|
||||
|
||||
private String streamUrl;
|
||||
private String userIdHash;
|
||||
private long streamDuration;
|
||||
private long streamPosition;
|
||||
|
||||
public BufferEventTask(String streamUrl, long streamDuration, long streamPosition, String userIdHash) {
|
||||
this.streamUrl = streamUrl;
|
||||
this.streamDuration = streamDuration;
|
||||
this.streamPosition = streamPosition;
|
||||
this.userIdHash = userIdHash;
|
||||
}
|
||||
|
||||
protected Void doInBackground(Void... params) {
|
||||
JSONObject requestBody = new JSONObject();
|
||||
try {
|
||||
requestBody.put("name", "buffer");
|
||||
requestBody.put("mobile", true);
|
||||
requestBody.put("url", streamUrl);
|
||||
requestBody.put("stream_duration", streamDuration);
|
||||
requestBody.put("stream_position", streamPosition);
|
||||
requestBody.put("user_id_hash", userIdHash);
|
||||
|
||||
RequestBody body = RequestBody.create(requestBody.toString(), Helper.JSON_MEDIA_TYPE);
|
||||
Request request = new Request.Builder().url(ENDPOINT).post(body).build();
|
||||
OkHttpClient client = new OkHttpClient.Builder().
|
||||
writeTimeout(60, TimeUnit.SECONDS).
|
||||
readTimeout(60, TimeUnit.SECONDS).
|
||||
build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
String responseString = response.body().string();
|
||||
Log.d(TAG, responseString);
|
||||
} catch (Exception ex) {
|
||||
// we don't want to fail if a buffer event fails to register
|
||||
Log.d(TAG, String.format("buffer event log failed: %s", ex.getMessage()), ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -119,6 +119,7 @@ import io.lbry.browser.model.UrlSuggestion;
|
|||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.browser.model.lbryinc.Reward;
|
||||
import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.tasks.BufferEventTask;
|
||||
import io.lbry.browser.tasks.CommentCreateWithTipTask;
|
||||
import io.lbry.browser.tasks.CommentListHandler;
|
||||
import io.lbry.browser.tasks.CommentListTask;
|
||||
|
@ -163,6 +164,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
WalletBalanceListener {
|
||||
private static final int RELATED_CONTENT_SIZE = 16;
|
||||
private static final String DEFAULT_PLAYBACK_SPEED = "1x";
|
||||
private static final String CDN_PREFIX = "https://cdn.lbryplayer.xyz";
|
||||
|
||||
private PlayerControlView castControlView;
|
||||
private Player currentPlayer;
|
||||
|
@ -290,6 +292,27 @@ public class FileViewFragment extends BaseFragment implements
|
|||
loadingNewClaim = false;
|
||||
}
|
||||
} else if (playbackState == Player.STATE_BUFFERING) {
|
||||
if (MainActivity.appPlayer != null && MainActivity.appPlayer.getCurrentPosition() > 0) {
|
||||
// we only want to log a buffer event after the media has already started playing
|
||||
String mediaSourceUrl = getStreamingUrl();
|
||||
long duration = MainActivity.appPlayer.getDuration();
|
||||
long position = MainActivity.appPlayer.getCurrentPosition();
|
||||
// TODO: Determine a hash for the userId
|
||||
String userIdHash = Lbryio.currentUser != null ? String.valueOf(Lbryio.currentUser.getId()) : "0";
|
||||
if (mediaSourceUrl.startsWith(CDN_PREFIX)) {
|
||||
BufferEventTask bufferEvent = new BufferEventTask(getStreamingUrl(), duration, position, userIdHash);
|
||||
bufferEvent.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
} else {
|
||||
// sdk stream buffer events should be handled differently
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("url", claim.getPermanentUrl());
|
||||
bundle.putLong("stream_duration", duration);
|
||||
bundle.putLong("stream_position", position);
|
||||
bundle.putString("user_id_hash", userIdHash);
|
||||
LbryAnalytics.logEvent(LbryAnalytics.EVENT_BUFFER, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
showBuffering();
|
||||
} else {
|
||||
hideBuffering();
|
||||
|
|
|
@ -11,6 +11,7 @@ public class LbryAnalytics {
|
|||
public static final String EVENT_APP_ERROR = "app_error";
|
||||
public static final String EVENT_APP_LAUNCH = "app_launch";
|
||||
public static final String EVENT_COMMENT_CREATE = "comment_create";
|
||||
public static final String EVENT_BUFFER = "buffer";
|
||||
public static final String EVENT_EMAIL_ADDED = "email_added";
|
||||
public static final String EVENT_EMAIL_VERIFIED = "email_verified";
|
||||
public static final String EVENT_FIRST_RUN_COMPLETED = "first_run_completed";
|
||||
|
|
Loading…
Add table
Reference in a new issue