我想在我的应用中使用facebook的默认视频播放器来流式传输facebook视频。点击视频,我想在我的应用程序中打开webview,并使用自己的视频播放器和所有默认控件播放Facebook视频。我将如何实现它?是他们以任何其他方式实现视频流。但我想使用Facebook默认播放器而不是任何其他播放器来播放视频。我怎样才能实现这一目标?任何帮助将不胜感激
答案 0 :(得分:2)
您是否已经仔细检查了dev facebook docs embedded-video-player/api,您可以在这里找到以下完整代码示例:
<html>
<head>
<title>Your Website Title</title>
</head>
<body>
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{your-app-id}',
xfbml : true,
version : 'v2.5'
});
// Get Embedded Video Player API Instance
var my_video_player;
FB.Event.subscribe('xfbml.ready', function(msg) {
if (msg.type === 'video') {
my_video_player = msg.instance;
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Your embedded video player code -->
<div
class="fb-video"
data-href="https://www.facebook.com/facebook/videos/10153231379946729/"
data-width="500"
data-allowfullscreen="true"></div>
</body>
</html>
假设您将此代码放在webview中,它通常会像魅力一样。
答案 1 :(得分:1)
用于加载动态网址
首先在你的html中替换为
--> data-href="{video_url}"
`mWebView.loadDataWithBaseURL(null, "<!DOCTYPE HTML>"
+ populateHTML(R.raw.my_html), "text/html", "UTF-8", null);private String populateHTML(int resourceID) {
String html;
html = readTextFromResource(resourceID);
html = html.replace("{video_url}", dynamic_url);
return html;
}`
private String readTextFromResource(int resourceID) {
InputStream raw = getResources().openRawResource(resourceID);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int i;
try {
i = raw.read();
while (i != -1) {
stream.write(i);
i = raw.read();
}
raw.close();
} catch (IOException e) {
e.printStackTrace();
}
return stream.toString();
}