Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d361aa93 authored by Mita Yun's avatar Mita Yun
Browse files

Do not merge Added added logging for audio/video in mediaplayer.java

Added eventlogs for the interval time and total time of audio and video
by user. Interval and total time will be logged when user pauses or
stops the media.

Change-Id: I5e50a38ce362aa527446a2cdaad1af6ff0fa9e66
parent 79128941
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ LOCAL_SRC_FILES += \
       core/java/android/speech/tts/EventLogTags.logtags \
       core/java/android/webkit/EventLogTags.logtags \
       telephony/java/com/android/internal/telephony/EventLogTags.logtags \
       media/java/android/media/EventLogTags.logtags \

# The following filters out code we are temporarily not including at all.
# TODO: Move AWT and beans (and associated harmony code) back into libcore.
+6 −0
Original line number Diff line number Diff line
option java_package android.media
# media service
270700 time_audio_played (time|2|3),(duration|2|3)
270705 total_audio_played (time|2|3),(duration|2|3)
270701 time_video_played (time|2|3),(duration|2|3)
270706 total_video_played (time|2|3),(duration|2|3)
+76 −1
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Set;
import java.lang.ref.WeakReference;
import android.os.SystemClock;
import android.util.TimeUtils;
import android.media.EventLogTags;
import java.lang.System;

/**
 * MediaPlayer class can be used to control playback
@@ -542,6 +546,17 @@ public class MediaPlayer
    private boolean mScreenOnWhilePlaying;
    private boolean mStayAwake;

    // logging
    private static final long MIN_MEDIA_TIME_MS = 10 * 1000;
    private static final int AUDIO = 0;
    private static final int VIDEO = 1;
    private long mTimeAudioPlayed;
    private long mTimeVideoPlayed;
    private long mPrevAudioPlayed;
    private long mPrevVideoPlayed;
    private long mTotalAudioPlayed = 0;
    private long mTotalVideoPlayed = 0;

    /**
     * Default constructor. Consider using one of the create() methods for
     * synchronously instantiating a MediaPlayer from a Uri or resource.
@@ -907,6 +922,7 @@ public class MediaPlayer
     * @throws IllegalStateException if it is called in an invalid state
     */
    public  void start() throws IllegalStateException {
        logMediaStarted();
        stayAwake(true);
        _start();
    }
@@ -920,6 +936,7 @@ public class MediaPlayer
     * initialized.
     */
    public void stop() throws IllegalStateException {
        logMediaStopped();
        stayAwake(false);
        _stop();
    }
@@ -933,6 +950,7 @@ public class MediaPlayer
     * initialized.
     */
    public void pause() throws IllegalStateException {
        logMediaPaused();
        stayAwake(false);
        _pause();
    }
@@ -1960,4 +1978,61 @@ public class MediaPlayer

    private OnInfoListener mOnInfoListener;

    private void logMediaStarted(){
        long currentTime = SystemClock.elapsedRealtime();
        // start playing video
        if (getVideoWidth() != 0) {
            mPrevVideoPlayed = currentTime;
        }
        // start playing audio
        else {
            mPrevAudioPlayed = currentTime;
        }
    }

    private void logMediaStopped() {
        long currentTime = SystemClock.elapsedRealtime();
        // playing video
        if (getVideoWidth() != 0) {
            mTimeVideoPlayed = currentTime - mPrevVideoPlayed;
            if (mTimeVideoPlayed >= MIN_MEDIA_TIME_MS) {
                mTotalVideoPlayed += mTimeVideoPlayed;
                mPrevVideoPlayed = 0;
                EventLogTags.writeTimeVideoPlayed(currentTime, mTimeVideoPlayed);
                EventLogTags.writeTotalVideoPlayed(currentTime, mTotalVideoPlayed);
            }
        }
        // playing audio
        else {
            mTimeAudioPlayed = currentTime - mPrevAudioPlayed;
            if (mTimeAudioPlayed >= MIN_MEDIA_TIME_MS) {
                mTotalAudioPlayed += mTimeAudioPlayed;
                mPrevAudioPlayed = 0;
                EventLogTags.writeTimeAudioPlayed(currentTime, mTimeAudioPlayed);
                EventLogTags.writeTotalAudioPlayed(currentTime, mTotalAudioPlayed);
            }
        }
    }

    private void logMediaPaused() {
        long currentTime = SystemClock.elapsedRealtime();
        // playing video
        if (getVideoWidth() != 0) {
            mTimeVideoPlayed = currentTime - mPrevVideoPlayed;
            if (mTimeVideoPlayed >= MIN_MEDIA_TIME_MS) {
                mTotalVideoPlayed += mTimeVideoPlayed;
                mPrevVideoPlayed = 0;
                EventLogTags.writeTimeVideoPlayed(currentTime, mTimeVideoPlayed);
            }
        }
        // playing audio
        else {
            mTimeAudioPlayed = currentTime - mPrevAudioPlayed;
            if (mTimeAudioPlayed >= MIN_MEDIA_TIME_MS) {
                mTotalAudioPlayed += mTimeAudioPlayed;
                mPrevAudioPlayed = 0;
                EventLogTags.writeTimeAudioPlayed(currentTime, mTimeAudioPlayed);
            }
        }
    }
}
 No newline at end of file