播放WebView视频从我的应用程序与其他应用程序的音乐
Play WebView video from my app with other app's music
我使用以下代码其工作正常播放Youtube视频与自动播放和静音功能,但当它播放视频然后我的音乐应用程序停止工作。一次只有一个在工作…
mWebView = (WebView) findViewById(R.id.web);
String videoURL = "https://www.youtube.com/embed/R52bof3tvZs";
String vid = "<html><body style='"margin: 0; padding: 0'"><iframe width='"100%'" height='"100%'" src='""+videoURL+"'" type='"text/html'" frameborder='"0'"></iframe><body><html>";
WebChromeClient mWebChromeClient = new WebChromeClient(){
public void onProgressChanged(WebView view, int newProgress) {
}
};
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.setWebChromeClient(mWebChromeClient);
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
mWebView.loadUrl("javascript:(function() { document.getElementsByTagName('video')[0].play(); })()");
}
});
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
if (Build.VERSION.SDK_INT < 17) {
Log.i("GPSNETWORK", "<17");
} else {
Log.i("GPSNETWORK", Build.VERSION.SDK_INT+">=17");
mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}
String myUrl = "<html><body style='margin:0px;padding:0px;'>'n" +
" <script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>'n" +
" var player;'n" +
" function onYouTubeIframeAPIReady()'n" +
" {player=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}'n" +
" function onPlayerReady(event){player.mute();player.setVolume(0);player.playVideo();}'n" +
" </script>'n" +
" <iframe id='playerId' type='text/html' width='1280' height='720''n" +
" src="+videoURL+"?enablejsapi=1&rel=0&playsinline=1&autoplay=1&showinfo=0&autohide=1&controls=0&modestbranding=1' frameborder='0'>'n" +
" </body></html>";
mWebView.loadData(""+Html.fromHtml(myUrl), "text/html", "UTF-8");`
请帮助我,提前感谢。
经过很长一段时间后,我修复了当玩家状态准备好时标记为真,并在我执行暂停时放置(检查)标志,它可以同时运行
String myUrl = "<html><body style='margin:0px;padding:0px;'>'n" +
" <script type='text/javascript' src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>'n" +
" var player;'n" +
" function onYouTubeIframeAPIReady()'n" +
" {player=new YT.Player('playerId',{events:{onReady:onPlayerReady, onStateChange: onPlayerStateChange}})}'n" +
" var done = false;'n" +
" function onPlayerReady(event){player.mute();player.setVolume(0);player.playVideo();done =
' " + bool(真正的)+"'"
;} ' n";
private boolean bool(boolean b)
{
you_tube_started = b;
Log.e(TAG, "you_tube_started "+you_tube_started);
return b;
}
这里像这样使用
if (mMediaPlayer != null && isPrepared) {
if (mMediaPlayer.isPlaying()) {
Log.w(TAG, "AUDIOFOCUS_LOSS : Nothing you_tube_started "+you_tube_started);
if(!you_tube_started)
pausePlayer();
pausedDueToAudioFocusLoss = true;
/*mMediaPlayer.stop();
mMediaPlayer.reset();*/
}
}
相关文章:
- Web应用程序,将成员状态更新为其他成员
- 通过绕过登录打开其他应用程序的内页
- 捕获在Windows应用程序中启动其他应用程序的用户事件
- 是否将PDF文件保存在其他应用程序可以访问的PhoneGap应用程序中?(iOS)
- 如果从我的网站在浏览器中安装了其他程序,如何在移动应用程序中打开共享对话框
- Express.js - 头盔.js和其他中间件,以及挂载的应用程序
- 想要在登录页面和其他页面应用程序 angularjs 之间分开
- 如何检查cookie是否存在,即使它是在其他应用程序中创建的?(使用 JS 或 C#)
- Angular SPA应用程序使其他URL仍然具有基于URL编号的突出显示导航栏部分
- Phonegap android 向其他应用程序用户发送通知
- RequireJS - 打包与主干相关的模块,以便在其他 Rails/JS 应用程序中重用
- Windows 10 应用 - 从应用内启动其他应用或本机 Windows 应用程序
- 在其他应用程序中打开应用程序
- 如何在应用程序模板中先加载 Ember 组件,然后再加载其他所有内容
- 构建大型jQuery移动Web应用程序:使用iFrames作为页面?骨干、骨干、下划线和其他框架
- 不允许打开除浏览器之外的任何其他应用程序
- 如何检查chrome应用程序是否安装在其他chrome应用程序中
- 登录到其他选项卡上的一个Web浏览器实例中的应用程序
- 如何使用JavaScript为其他苹果设备自动注册应用程序
- 如果无法访问其他服务器,Node.js应用程序将退出.如何防止应用程序停止