在处理数字标牌项目时,我们必须提供显示纵向图像和视频的功能。虽然图像效果很好,但视频会让我们的 Minix Neo x9 播放器做出奇怪的事情。
播放器不仅可以改变视频视图或应用程序的旋转,而且在以纵向模式播放视频后整个Android系统都会旋转。
的AndroidManifest.xml
<activity
android:name="com.example"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme"
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:screenOrientation="portrait"
>
fragment_video.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="0">
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</FrameLayout>
VideoFragment.java
public class VideoFragment extends Fragment {
private final String TAG = VideoFragment.class.toString();
// Container Activity must implement this interface
public interface OnVideoStateListener {
public void onVideoCompleted(String slideId);
}
private OnVideoStateListener videoStateListener;
private VideoView videoView;
private MediaController mediaController;
public static VideoFragment newInstance(String location, String slideId) {
VideoFragment f = new VideoFragment();
Bundle args = new Bundle();
args.putString("location", location);
args.putString("slideId", slideId);
f.setArguments(args);
return f;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
Log.d(TAG, "onAttach: " + activity);
this.mediaController = new MediaController(activity);
this.mediaController.setVisibility(View.GONE);
this.mediaController.setAnchorView(videoView);
try {
this.videoStateListener = (OnVideoStateListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(
activity.toString() + " must implement OnVideoStateListener");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_video, container, false);
this.videoView = (VideoView)view.findViewById(R.id.video);
this.videoView.setMediaController(mediaController);
return view;
}
@Override
public void onDetach() {
this.videoStateListener = null;
if(this.videoView.isPlaying()){
this.videoView.stopPlayback();
}
this.videoView.setMediaController(null);
this.mediaController = null;
super.onDetach();
}
public void onStart(){
super.onStart();
String location = getArguments().getString("location");
String slideId = getArguments().getString("slideId");
this.showVideo(location, slideId);
}
private void showVideo(String location, final String slideId){
Log.d(TAG, "showVideo(slideId=" + slideId + "): location: " + location);
File videoFile = new File(location);
if (videoFile.exists()) {
String absVideoPath = "file://" + videoFile.getAbsolutePath();
this.videoView.setVideoPath(absVideoPath);
} else {
Log.e(TAG, "showVideo: videoFile not found:" + location);
callbackFinished(slideId);
return;
}
this.videoView.requestFocus();
this.videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(TAG, "showVideo: onError:" + mp);
callbackFinished(slideId);
return false;
}
});
this.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.i(TAG, "showVideo: onPrepared:" + mp);
mp.seekTo(0);
mp.setLooping(false);
mp.start();
}
});
this.videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.i(TAG, "showVideo: onCompletion:" + mp);
callbackFinished(slideId);
}
});
}
private void callbackFinished(String slideId){
if(videoStateListener != null){
videoStateListener.onVideoCompleted(slideId);
}
}
}
之前有没有人遇到过这类问题?
答案 0 :(得分:0)
从硬件提供商处获得反馈。说这是默认固件中的一个错误。