我尝试使用 VideoView 创建一个简单的应用来播放全屏HLS,
这是代码:
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;
public class FullScreenActivity extends Activity implements OnTouchListener {
private VideoView fullVideoView;
private String URL = "http://win.stream.netmedia.co.id/live/nettv_low/index.m3u8";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_fullscreen);
fullVideoView = (VideoView) findViewById(R.id.vv);
fullVideoView.setOnTouchListener(this);
fullVideoView.setVideoURI(Uri.parse(URL));
fullVideoView.requestFocus();
// fullVideoView.start(); <-- I have tried it, but still not work
}
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// This code will start/paused the videoview when videoview is touched
if (arg1.getAction() == MotionEvent.ACTION_DOWN)
if (fullVideoView.isPlaying()) {
fullVideoView.pause();
} else {
fullVideoView.start();
}
return true;
}
}
此代码完全适用于Jelly Bean。
但由于某些原因,此代码不适用于KitKat
我在同一台设备上尝试了Jelly Bean和KitKat上的代码
有人可以解释为什么这段代码不适用于KitKat吗?
下面是日志文件,在我关闭应用程序之前,它会一直发送垃圾邮件。
01-14 18:15:58.502: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.504: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.505: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.518: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.521: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.522: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.534: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.536: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.537: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.550: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.552: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.553: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.566: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.568: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.569: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.582: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.584: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.585: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.598: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.600: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.601: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.614: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.617: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.618: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.630: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.632: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.633: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.647: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.649: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.650: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.662: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.664: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.665: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.678: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.680: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.681: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.694: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.696: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.697: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.710: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.713: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.713: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.726: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.728: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.729: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.743: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.745: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>
01-14 18:15:58.746: D/OpenGLRenderer(25875): finish <0x6567e698>
01-14 18:15:58.758: I/SurfaceView(25875): updateWindow -- OnPreDrawListener, mHaveFrame = true
01-14 18:15:58.760: D/OpenGLRenderer(25875): prepareDirty (0.00, 0.00, 1280.00, 736.00) opaque 1 <0x6567e698>