更新时间:2023-11-26 15:19:16
webview和native之间的通信是通过JavascriptInterface完成的.***以类似的方式构建了它的API.您可以使用以下代码实现所需的功能.
The communication between webview and native are done through JavascriptInterface. *** has built it's API in a similar fashion. you can use the below code to achieve what you want.
要通过***视频实现播放/暂停功能,您可以使用 *** JavaScript Player API
To achieve the play/pause functionality via *** video you can use *** JavaScript Player API.
示例:
<div id="video-placeholder"></div>
<script src="https://www.***.com/iframe_api"></script>
API完全加载后,它将查找您应定义的名为 on***IframeAPIReady()
的全局函数.
When the API is fully loaded, it looks for a global function called on***IframeAPIReady()
which you should define.
您的代码应如下所示
var player;
function on***IframeAPIReady() {
player = new YT.Player('video-placeholder', {
width: 600,
height: 400,
videoId: 'Xa0Q0J5tOP0',
playerVars: {
color: 'white',
playlist: 'taJ60kskkns,FG0fTKAqZ5g'
},
events: {
onReady: initialize
}
});
}
只需单击两个按钮,然后单击单击即可调用所需的方法.
Just make two buttons and call the needed method on click.
$('#play').on('click', function () {
player.playVideo();
});
$('#pause').on('click', function () {
player.pauseVideo();
});
您可以使用 JavascriptInterface 在本机java/中获取回调WebView中的kotlin代码.
You can use JavascriptInterface to get the callback inside the native java/kotlin code from WebView.
更多详细信息
JavaScript接口(示例)