1

I am using HTML5 video tag with mp4 video, some phone playing this video good... nut some phone not playing this video...

i have doubt that inside the application which video player will work to play? have any inbuily video player or need to install any codec for that or it using browser video player?

Dhamu
  • 1,694
  • 5
  • 22
  • 47

1 Answers1

1

It uses phone's codecs only. Problem is while decoding as it is not using android videoview and overlay.

Try setting harwareacceleration to true for you app. It should work. But some phones may not have hardware acceleration and so the decode fails.

But correct approach is to write the android videoplayer to play view like this:

VideoPlayerActivity.java:

package com.camera.manual;

import android.app.Activity; import android.content.pm.ActivityInfo; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.view.WindowManager; import android.widget.MediaController; import android.widget.Toast; import 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> 

and in JavaScriptInterface define a function like this:

public void launchVideoView () {

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

Then call this function when you have to play video

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Sushil
  • 8,250
  • 3
  • 39
  • 71