在Android中播放facebook视频网址

时间:2014-04-22 05:44:36

标签: android facebook android-webview android-videoview

我正试图在 videoView 以及 webview 中播放facebook视频网址: -

1。在VideoView中

    VideoView videoView = (VideoView) findViewById(R.id.videoView);
     //Use a media controller so that you can scroll the video contents
     //and also to pause, start the video.
     MediaController mediaController = new MediaController(this);
     mediaController.setAnchorView(videoView);
     videoView.setMediaController(mediaController);
     videoView.setVideoURI(Uri.parse("https://www.facebook.com/video/embed?video_id=641390085951248"));
     videoView.start();

2。在WebView中

    WebView webView = (WebView) findViewById(R.id.webView);
    final WebSettings settings = webView.getSettings();
    settings.setDefaultTextEncodingName("utf-8");
    settings.setJavaScriptEnabled(true);
    webView.loadUrl("https://www.facebook.com/video/embed?video_id=641390085951248");

并在清单文件中定义Internet权限。

但我无法播放我的facebook videoUrl。

请评论它。

Hello Guys,我找到了一个VideoPlayer代码并运行它,但无法播放它。

public class VideoPlayer extends Activity {

    ProgressDialog mProgress;
    VideoView video;
    int second;
    static int length;
    Button replay_button;
    OnCancelListener oncancel;

    /*
     * PowerManager manager; PowerManager.WakeLock wl;
     */

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.video_player);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        String url = getIntent().getStringExtra("url");
        video = (VideoView) findViewById(R.id.videoView1);

        /*
         * manager = (PowerManager) getSystemService(Context.POWER_SERVICE); wl
         * = manager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
         * "Your Tag"); wl.acquire();
         */

        replay_button = (Button) findViewById(R.id.replayButton);

        oncancel = new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub
                finish();
            }
        };

        try {
            mProgress = new ProgressDialog(VideoPlayer.this);

        } catch (Exception e) {
            // TODO: handle exception
        }

        MediaController mediaController = new MediaController(VideoPlayer.this);
        mediaController.setAnchorView(video);
        video.setMediaController(mediaController);
        video.setKeepScreenOn(true);
        video.setVideoPath(url);
        video.requestFocus();
        video.start();
        video.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub
                replay_button.setVisibility(View.GONE);
                return false;
            }
        });

        video.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                try {
                    if (mProgress != null) {
                        mProgress.dismiss();
                    }

                    video.start();

                } catch (Exception e) {
                    // TODO: handle exception

                }

            }
        });
        DialogInterface.OnCancelListener cancel = new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                // TODO Auto-generated method stub
                finish();

            }
        };

        video.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub
                try {
                    showMessage("Message", "Sorry,This Video can not be played.");
                } catch (Exception e) {
                    // TODO: handle exception
                }

                return true;
            }
        });

        video.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer arg0) {
                // TODO Auto-generated method stub
                try {

                    replay_button.setVisibility(View.VISIBLE);
                    replay_button.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                            // TODO Auto-generated method stub

                            video.start();
                            replay_button.setVisibility(View.GONE);
                        }
                    });

                } catch (Exception e) {
                    // TODO: handle exception
                }

            }
        });

        /*
         * timess tiktok = new timess(1000000000, 1000); tiktok.start();
         */

    }

    @SuppressLint("NewApi")
    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        super.onBackPressed();
        // Log.i(" back key pressed","keyPressed");
        try {
            if (mProgress != null) {
                mProgress.dismiss();
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        // wl.release();
        finish();

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        video.pause();
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        video.start();
        super.onRestart();
    }

    @Override
    public void onResume() {
        super.onResume();
        replay_button.setVisibility(View.GONE);
    }

    private void showMessage(String title, String message) {
        try {
            AlertDialog.Builder alt_bld = new AlertDialog.Builder(VideoPlayer.this);
            alt_bld.setTitle(title);
            alt_bld.setMessage(message);
            alt_bld.setCancelable(false);
            alt_bld.setNeutralButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    finish();
                    dialog.dismiss();

                }
            });
            alt_bld.show();
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}

1 个答案:

答案 0 :(得分:0)

看起来Facebook视频播放器使用的是Adobe Flash不支持的Adobe Flash。