在Android中播放Facebook视频? [英] Playing facebook video in Android?
本文介绍了在Android中播放Facebook视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Android中是否可以通过自动播放播放Facebook视频?
Is there any way to play facebook video with autoplay in Android?
我厌倦了使用WebView,但似乎html5移动版不允许自动播放视频.
I tired to use WebView, but it seems html5 mobile does not allow auto play video.
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
mainWebView.setWebChromeClient(new WebChromeClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("https://www.facebook.com/video/embed?video_id=10154623311598812");
推荐答案
以下是可在Android中使用的不错的Video Player库:
https://github.com/brianwernick/ExoMedia
Here is a nice Video Player library available in Android:
https://github.com/brianwernick/ExoMedia
请查看其演示代码以了解如何集成它.
Please see its demo code to see how to integrate it.
请注意,它不使用 HTML5
.
像这样定义一个布局,说一个activity_video_player:
Define a layout say activity_video_player like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:EMVideoView="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.devbrackets.android.exomedia.EMVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
EMVideoView:defaultControlsEnabled="true"/>
</FrameLayout>
然后 Activity
这样说 VideoPlayerActivity
:
public class VideoPlayerActivity extends AppCompatActivity implements MediaPlayer.OnPreparedListener
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
.
.
String videoUrl = "url";
mVideoView.setOnPreparedListener(this);
mVideoView.setVideoURI(Uri.parse(videoUrl));
}
@Override
public void onPrepared(MediaPlayer mp) {
mVideoView.start();
}
}
就是这样.让魔术发生.
That's it. Let the magic happen.
这篇关于在Android中播放Facebook视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文