【问题标题】:VideoView error only on real deviceVideoView 错误仅在真实设备上
【发布时间】:2012-12-16 23:02:43
【问题描述】:

在片段中,我有 videoview 并播放录制的 whit 模拟器相机 .mp4 视频。一切都很好,在模拟器中视频正在播放,但是在真实设备上,当我尝试播放另一个视频时,再次以 .mp4 格式用我的相机录制,屏幕变黑并黯然失色“BitmapFactory 类。找不到源”。我正在 4.0.4 设备上进行测试,目标是 8 到 17 api。图像在模拟器和真实设备上都可以正常打开。没有LOGcat错误,一切都是绿色的……

片段代码

public class PreviewFragment extends Fragment {
View view;
//variable
File file;
boolean image;
//views
VideoView videView;
ImageView imageView;
ImageButton imageButton;

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if(container == null) {
        return null;
    }
    view = inflater.inflate(R.layout.fragment_preview, container, false);
    //elements
    imageView = (ImageView) view.findViewById(R.id.imageView1);
    videView = (VideoView) view.findViewById(R.id.videoView1);
    //variables from activity
    file = ((PreviewActivity)getActivity()).file;
    image = ((PreviewActivity)getActivity()).image;


    //main run
    if(image == true) {
        imageView.setImageURI(Uri.parse(file.getAbsolutePath()));
    }
    else {
        videView.setVideoURI(Uri.parse(file.getAbsolutePath()));
        videView.setMediaController(new MediaController(getActivity()));
        videView.requestFocus();
        videView.start();
    }

    return view;
}
}

和xml代码

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" >

<VideoView
    android:id="@+id/videoView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:contentDescription="@string/text_fullscreen" />

【问题讨论】:

    标签: android android-videoview


    【解决方案1】:

    奇怪,但是,在 4.1 的模拟器中,如果我在片段中播放视频,但在真正的 4.0 设备上,视频必须在活动中播放,这样视频在模拟器和真实设备中播放。不知道为什么,但它是这样工作的。

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多