Skip to content

容器迭代二 #13

@army8735

Description

@army8735

后台播放音频功能

js接口调用方式

ZhuanQuanJSBridge.call('media', data: JSON, function(res) {
  // 回调
});

其中data的格式有几种情况

传递信息给后台播放器

{
  key: "info",
  value: {
    url: "音频地址",
    id: "音频id",
  },
}

逻辑细节:

  • 尝试使用边播边缓存,即播放过的内容缓存下来,下次再播可以节省网络请求。播放过的内容可能为整首音乐,也可能是一首音乐的一部分(如前10秒)。android中结合使用了EXOPlayer+OKHttp,http网络请求及缓存功能由OKHttp实现。
  • 每次调用时判断id和上一次是否相同,如是则说明同一首,直接略过后续逻辑;如否将url传递给后台播放器,同时停止之前可能正在播放的音乐。

播放

{
  key: "play",
}
{
  key: "play",
  value: {
    url: "音频地址",
    id: "音频id",
  },
}

逻辑细节:

暂停

{
  key: "pause",
}

逻辑细节:

  • 暂停当前播放的音乐,保持住当前的信息(如播放时间位置)。
  • 调用结束后,进行回调,将id作为参数传回,同上。

停止

{
  key: "stop",
}

逻辑细节:

  • 停止当前播放的音乐,播放进度清零但保持住当前的信息(如播放url和id)。
  • 调用结束后,进行回调,将id作为参数传回,同上。

停止并释放资源

{
  key: "release",
}

逻辑细节:

  • 停止当前播放的音乐,释放资源和清空信息(如url和id和记录的上次播放id)。
  • 调用结束后,进行回调,将id作为参数传回,同上。

跳转到特定时间位置进行播放

{
  key: "seek",
  value: {
    time: int, // 秒数
  },
}

逻辑细节:

  • 播放进度跳到多少秒
  • 调用结束后,进行回调,将id作为参数传回,同上。

其它

当传递的data或者key为空或者key为其它值时,忽略,此举为兼容老版android特定逻辑使用。

播放加载时的事件

这些事件均发送给当前的view(最上层可见活动view)的webview。

mediaPrepared

传递info后,播放器加载资源得到媒体信息(duration时长毫秒)后发出,附上id和duration信息:https://github.com/uyutech/android/blob/fragment/app/src/main/java/cc/circling/MediaService.java#L146-L150

mediaProgress

传递info后,播放器加载资源的进度,附上id、percent(已加载百分比)、duration、position(已加载时长毫秒):https://github.com/uyutech/android/blob/fragment/app/src/main/java/cc/circling/MediaService.java#L130-L137

mediaEnd

当播放到末尾时调用,附上id信息:https://github.com/uyutech/android/blob/fragment/app/src/main/java/cc/circling/MediaService.java#L156-L158
特别注意音乐停止后可能会再调用一次play方法,此时要求音乐从头重新播放。android做法为停止时将播放器seek时间变为0。

mediaTimeupdate

在播放音乐时,发送当前播放时间,附上id、currentTime(当前播放时间毫秒)、duration、percent:https://github.com/uyutech/android/blob/fragment/app/src/main/java/cc/circling/MediaService.java#L197-L203

其它小优化调整

针对webview在进出前后台时的操作

如果可行,当每个页面的view进入后台时(按下Home键,或者有新的view进行pushwindow盖在当前view上面),其所包含的webview暂停运行js(android为调用webview.onPause()方法);反之恢复到前台时,恢复js运行(android为调用webview.onResume()方法)。

webview中视频全屏自动横屏

android自动,ios为竖屏。https://www.jianshu.com/p/f1a0b96fb03a

修复一个ios9机子无法启动的bug

2018-03-10 13:49:27.797 ZQuanProject[580:193744] -[AppDelegate modifyWebViewUserAgent] [Line 67] new agent :Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13G36 app/ZhuanQuan/0.5.4
2018-03-10 13:49:27.814 ZQuanProject[580:193744] UMLOG: analytics sdk version 4.2.4 , app version 0.5.4
2018-03-10 13:49:28.046 ZQuanProject[580:193744] Reachability Flag Status: WR t------ networkStatusForFlags
2018-03-10 13:49:28.405 ZQuanProject[580:193744] UMLOG: logEntry=sdk_version:4.2.4, device_id:ca3aaaf9f4d819d78c07b535e00383db0c6589f2, model:iPhone7,2, os_version:9.3.5, active_user:(null), active_msg:(null), cc:(null), sessions:(null), ekv:(null)
2018-03-10 13:49:28.481 ZQuanProject[580:193744] UMLOG: prepare to post log data
2018-03-10 13:49:28.483 ZQuanProject[580:193744] UMLOG: session begin:A7D14E3085BB4ABB308394654FC67542
2018-03-10 13:49:28.485 ZQuanProject[580:193744] -[JZNetObserver observeNetStatus]_block_invoke [Line 38] 有网
2018-03-10 13:49:28.500 ZQuanProject[580:193744] -[UnzipManager zipArchiveWillUnzipArchiveAtPath:zipInfo:] [Line 133] 将要解压。
2018-03-10 13:49:28.800 ZQuanProject[580:193927] UMLOG: (Response Applog) {"success": "ok"}
2018-03-10 13:49:29.315 ZQuanProject[580:193744] -[UnzipManager releaseZipFilesWithUnzipFileAtPath:Destination:] [Line 113] unzipPath = /var/mobile/Containers/Data/Application/8B55B0DB-F8E4-49D4-8D00-0A0CB94C88D7/Library/Caches/h5
2018-03-10 13:49:29.315 ZQuanProject[580:193744] -[UnzipManager releaseZipFilesWithUnzipFileAtPath:Destination:] [Line 114] 解压成功并覆盖!
2018-03-10 13:49:29.448 ZQuanProject[580:193744] UMLOG: beginbg id:1
2018-03-10 13:49:29.473 ZQuanProject[580:193744] UMLOG: session: session_id=A7D14E3085BB4ABB308394654FC67542, duration=1.331871
2018-03-10 13:49:29.473 ZQuanProject[580:193744] UMLOG: session end:A7D14E3085BB4ABB308394654FC67542
2018-03-10 13:49:29.473 ZQuanProject[580:193744] UMLOG: smart policy enter while background
2018-03-10 13:49:29.492 ZQuanProject[580:193744] UMLOG: logEntry=sdk_version:4.2.4, device_id:ca3aaaf9f4d819d78c07b535e00383db0c6589f2, model:iPhone7,2, os_version:9.3.5, active_user:(null), active_msg:(null), cc:(null), sessions:(
        {
        autopages =         (
                        {
                duration = 1172;
                "page_name" = ZQLaunchViewController;
            }
        );
        duration = 1342;
        "end_time" = 1520660969449;
        id = A7D14E3085BB4ABB308394654FC67542;
        "start_time" = 1520660968107;
    }
), ekv:(null)
2018-03-10 13:49:29.592 ZQuanProject[580:193744] UMLOG: prepare to post log data
2018-03-10 13:49:29.599 ZQuanProject[580:193744] UMLOG: save cache done
2018-03-10 13:49:29.633 ZQuanProject[580:193744] UMLOG: endbg id:1
2018-03-10 13:49:29.635 ZQuanProject[580:193744] UMLOG: session begin:D067BF91D023F66E1EEBADB3DB4B7960
2018-03-10 13:49:29.651 ZQuanProject[580:193947] UMLOG: (Response Applog) {"success": "ok"}
2018-03-10 13:49:30.786 ZQuanProject[580:193744] [Bugly]  Trapped uncaught exception 'NSInternalInconsistencyException', reason: 'UIRefreshControl may only be managed by a UITableViewController' 
(
	0   CoreFoundation                      0x0000000183da2dc8 <redacted> + 148
	1   libobjc.A.dylib                     0x0000000183407f80 objc_exception_throw + 56
	2   CoreFoundation                      0x0000000183da2cf8 <redacted> + 0
	3   UIKit                               0x000000018907ff78 <redacted> + 332
	4   UIKit                               0x0000000188efeed4 <redacted> + 556
	5   UIKit                               0x0000000188efeba8 <redacted> + 504
	6   UIKit                               0x0000000188f0c678 <redacted> + 1784
	7   ZQuanProject                        0x000000010007eb0c -[ZQUIWebViewController setRefreshState:] + 768
	8   ZQuanProject                        0x000000010007c634 -[ZQUIWebViewController viewDidLoad] + 228
	9   UIKit                               0x0000000188f04c40 <redacted> + 996
	10  UIKit                               0x0000000188fc5230 <redacted> + 72
	11  UIKit                               0x0000000188fc5108 <redacted> + 416
	12  UIKit                               0x0000000188fc4350 <redacted> + 144
	13  UIKit                               0x0000000188fc3ef4 <redacted> + 868
	14  UIKit                               0x0000000188fc3b1c <redacted> + 60
	15  UIKit                               0x0000000188fc3a84 <redacted> + 208
	16  UIKit                               0x0000000188f001e4 <redacted> + 656
	17  QuartzCore                          0x000000018688e98c <redacted> + 148
	18  QuartzCore                          0x00000001868895c8 <redacted> + 292
	19  QuartzCore                          0x0000000186889488 <redacted> + 32
	20  QuartzCore                          0x0000000186888ab8 <redacted> + 252
	21  QuartzCore                          0x0000000186888818 <redacted> + 500
	22  QuartzCore                          0x0000000186881ddc <redacted> + 80
	23  CoreFoundation                      0x0000000183d58728 <redacted> + 32
	24  CoreFoundation                      0x0000000183d564cc <redacted> + 372
	25  CoreFoundation                      0x0000000183d568fc <redacted> + 928
	26  CoreFoundation                      0x0000000183c80c50 CFRunLoopRunSpecific + 384
	27  GraphicsServices                    0x0000000185568088 GSEventRunModal + 180
	28  UIKit                               0x0000000188f6e088 UIApplicationMain + 204
	29  ZQuanProject                        0x0000000100068bc8 main + 124
	30  libdyld.dylib                       0x000000018381e8b8 <redacted> + 4
)
2018-03-10 13:49:31.829 ZQuanProject[580:193744] UMLOG: error: session_id=D067BF91D023F66E1EEBADB3DB4B7960, context=UIRefreshControl may only be managed by a UITableViewController
(null)
((
	0   CoreFoundation                      0x0000000183da2dc8 <redacted> + 148
	1   libobjc.A.dylib                     0x0000000183407f80 objc_exception_throw + 56
	2   CoreFoundation                      0x0000000183da2cf8 <redacted> + 0
	3   UIKit                               0x000000018907ff78 <redacted> + 332
	4   UIKit                               0x0000000188efeed4 <redacted> + 556
	5   UIKit                               0x0000000188efeba8 <redacted> + 504
	6   UIKit                               0x0000000188f0c678 <redacted> + 1784
	7   ZQuanProject                        0x000000010007eb0c -[ZQUIWebViewController setRefreshState:] + 768
	8   ZQuanProject                        0x000000010007c634 -[ZQUIWebViewController viewDidLoad] + 228
	9   UIKit                               0x0000000188f04c40 <redacted> + 996
	10  UIKit                               0x0000000188fc5230 <redacted> + 72
	11  UIKit                               0x0000000188fc5108 <redacted> + 416
	12  UIKit                               0x0000000188fc4350 <redacted> + 144
	13  UIKit                               0x0000000188fc3ef4 <redacted> + 868
	14  UIKit                               0x0000000188fc3b1c <redacted> + 60
	15  UIKit                               0x0000000188fc3a84 <redacted> + 208
	16  UIKit                               0x0000000188f001e4 <redacted> + 656
	17  QuartzCore                          0x000000018688e98c <redacted> + 148
	18  QuartzCore                          0x00000001868895c8 <redacted> + 292
	19  QuartzCore                          0x0000000186889488 <redacted> + 32
	20  QuartzCore                          0x0000000186888ab8 <redacted> + 252
	21  QuartzCore                          0x0000000186888818 <redacted> + 500
	22  QuartzCore                          0x0000000186881ddc <redacted> + 80

	23  CoreFoundation                      0x0000000183d58728 <redacted> + 32
	24  CoreFoundation                      0x0000000183d564cc <redacted> + 372
	25  CoreFoundation                      0x0000000183d568fc <redacted> + 928
	26  CoreFoundation                      0x0000000183c80c50 CFRunLoopRunSpecific + 384
	27  GraphicsServices                    0x0000000185568088 GSEventRunModal + 180
	28  UIKit                               0x0000000188f6e088 UIApplicationMain + 204
	29  ZQuanProject                        0x0000000100068bc8 main + 124
	30  libdyld.dylib                       0x000000018381e8b8 <redacted> + 4
)

dSYM UUID: 98DF27CE-4CD4-379F-AEA7-F9B0161B433E
CPU Type: arm64
Slide Address: 0x0000000100000000
Binary Image: ZQuanProject
Base Address: 0x0000000100060000
2018-03-10 13:49:31.849 ZQuanProject[580:193744] UMLOG: session: session_id=D067BF91D023F66E1EEBADB3DB4B7960, duration=2.209834
libc++abi.dylib: terminate_handler unexpectedly threw an exception
(lldb) 

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions