php录音时长统计,音频app阅读时长统计分析

描述

分析学习喜马拉雅app阅读时长统计机制,并应用到自己app中去

分析

使用抓包工具charles观测app统计发送时机,发现切换音频源,或本地缓存有阅读数据进入首页app时发送(nyx/v2/track/statistic/android)

d62f575306ba

image

播放过程中,查看本地播放时长记录,发现每隔一段时间向本地SharePreferences保存阅读时长数据,并且发现mListenedDuration大概每隔5秒变化一次,切换音频发送成功后,本地缓存相应条目被删除

adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android\:player.xml

播放过程中,杀掉进程。后重启会发送本地缓存的记录,并清除本地条目

音频播放及切换音频源本地缓存数据变化

读取本地播放时长记录

使用代码代替adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android:player.xml mListenedDuration每个5秒观测动作

#!/usr/bin/python

# -*- coding: UTF-8 -*-

import os

import datetime

import json

import time

def fenxi():

cmd = "adb shell cat /data/data/com.ximalaya.ting.android/shared_prefs/uploaders_com.ximalaya.ting.android\:player.xml"

timeStr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

# time = datetime.datetime.strptime(string,'%Y-%m-%d %H:%M:%S')

print("*" * 50 + "start:" + timeStr)

f = os.popen(cmd)

if f:

content = f.read()

# print(content)

content = content.replace(""", '"')

# print(content)

startIndex = content.find("[{")

endIndex = content.rfind("}]")

if startIndex != -1 and endIndex != -1:

# print(startIndex, endIndex)

content = content[startIndex:endIndex + 2]

# print(content)

jsonContent = json.loads(content)

# print(jsonContent)

for ct in jsonContent:

# print(ct)

mListenedDuration = ct.get('xmPlayRecord').get('mListenedDuration')

mSendDataTime = ct.get('xmPlayRecord').get('mSendDataTime')

mDuration = ct.get('xmPlayRecord').get('mDuration')

mStartTime = ct.get('xmPlayRecord').get('mStartTime')

mStartedPosition = ct.get('xmPlayRecord').get('mStartedPosition')

playUrl = ct.get('xmPlayRecord').get('playUrl')

mPlaySource = ct.get('xmPlayRecord').get('mPlaySource')

# timeArray = time.strptime(mStartTime, "%Y-%m-%d %H:%M:%S")

print("mListenedDuration=%s"%mListenedDuration)

print("mDuration=%s"%mDuration)

print("mSendDataTime=%s"%mSendDataTime)

print("mStartTime=%s"%mStartTime)

print("mStartedPosition=%s"%mStartedPosition)

print("playUrl=%s"%playUrl)

# print("mPlaySource=%s"%mPlaySource)

else:

print("无数据")

timeStr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

print("*" * 50 + "end:" + timeStr)

print("\n" * 2)

# nyx/v2/track/statistic/android

def main():

while True:

fenxi()

time.sleep(3)

if __name__ == "__main__":

main()

观测终端输出结果

**************************************************start:2018-09-29 15:27:10

mListenedDuration=9

mDuration=9

mSendDataTime=0

mStartTime=1538206021312

mStartedPosition=0

playUrl=http://audio.xmcdn.com/group36/M02/0E/9D/wKgJUlo3b7aiMSvIANicyKRiMZ4986.m4a

**************************************************end:2018-09-29 15:27:10

**************************************************start:2018-09-29 15:27:13

无数据

**************************************************end:2018-09-29 15:27:14

**************************************************start:2018-09-29 15:27:17

mListenedDuration=0

mDuration=0

mSendDataTime=0

mStartTime=1538206035483

mStartedPosition=0

playUrl=http://audio.xmcdn.com/group31/M0B/6C/F8/wKgJX1mG0w-Q7DXpAM_ILYxT6gU048.m4a

**************************************************end:2018-09-29 15:27:17

**************************************************start:2018-09-29 15:27:20

mListenedDuration=5

mDuration=5

mSendDataTime=0

mStartTime=1538206035483

mStartedPosition=0

playUrl=http://audio.xmcdn.com/group31/M0B/6C/F8/wKgJX1mG0w-Q7DXpAM_ILYxT6gU048.m4a

**************************************************end:2018-09-29 15:27:20

分析结果

d62f575306ba

image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值