1

我正在使用带有 mp4 视频的 HTML5 视频标签,一些手机播放这个视频很好......坚果一些手机没有播放这个视频......

我怀疑在应用程序中哪个视频播放器可以播放?有任何内置的视频播放器或需要为此安装任何编解码器或使用浏览器视频播放器?

4

1 回答 1

1

它仅使用手机的编解码器。问题是在解码时,因为它没有使用 android videoview 和覆盖。

尝试为您的应用设置 harwareacceleration 为 true。它应该工作。但是有些手机可能没有硬件加速,所以解码失败。

但正确的方法是编写 android videoplayer 来播放视图,如下所示:

VideoPlayerActivity.java:

包 com.camera.manual;

导入android.app.Activity;导入android.content.pm.ActivityInfo;导入android.net.Uri;导入android.os.Bundle;导入android.util.Log;导入android.view.Window;导入android.view.WindowManager;导入 android.widget.MediaController;导入 android.widget.Toast;导入android.widget.VideoView;

public class VideoPlayerActivity extends Activity {

    private boolean mResumed = false;
    private boolean mFocused = false;
    private boolean mControlResumed = false;
    private VideoView videoView = null;
    private int stopPosition = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.Theme_TransparentVideo);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

        setContentView(R.layout.video_view);

        videoView =(VideoView)findViewById(R.id.myvideoview);
        MediaController mediaController= new MediaController(this);
        mediaController.setAnchorView(videoView);        
        Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.slow);        
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);        
        videoView.requestFocus();
        videoView.start();
    }

    @Override
    public void onPause() {
        super.onPause();
        mResumed = false;
        if (mControlResumed) {
            if (null != videoView)
                videoView.pause();
            stopPosition = videoView.getCurrentPosition();
            mControlResumed = false;
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        mResumed = true;
        if (mFocused && mResumed && !mControlResumed) {
            if(null != videoView) {
                //videoView.resume();
                videoView.seekTo(stopPosition);
                videoView.start();
            }
            mControlResumed = true;
        }
    }


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        mFocused = hasFocus;
        if (mFocused && mResumed && !mControlResumed) {
            if (null != videoView) {
                //videoView.resume();
                videoView.seekTo(stopPosition);
                videoView.start();
            }
            mControlResumed = true;
        }
    }
} 

video_view.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<VideoView android:id="@+id/myvideoview"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_gravity="center" />

</FrameLayout> 

并在 JavaScriptInterface 中定义一个这样的函数:

public void launchVideoView () {

    Intent intent = new Intent();
    intent.setClass(mContext, VideoPlayerActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    mContext.startActivity(intent);
}

然后在必须播放视频时调用此函数

于 2013-08-22T10:01:26.513 回答