我使用自定义视频视图。但问题是我可以在我的应用程序中听到收音机但没有显示任何内容,只是黑屏。
所以我试着看日志,我得到了像
这样的错误当我尝试连接该网站时,我可以获得.avi文件。它运作良好。
但我不知道我错过了什么..
我附上了我的.java和.xml来源。
.java来源
public class ExerciseFragment
extends Fragment {
private String uri = null;
public MyVideoView videoView;
private WebService ws = new WebService();
private CustomMediaController localCustomMediaController = null;
public void onConfigurationChanged(Configuration paramConfiguration) {
super.onConfigurationChanged(paramConfiguration);
if (paramConfiguration.orientation == 2) {
this.videoView.isFull = true;
}
while (paramConfiguration.orientation != 1) {
return;
}
this.videoView.isFull = false;
}
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
paramBundle = getArguments();
if (paramBundle != null) {
this.uri = paramBundle.getString("uri");
}
}
@Nullable
public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
View view = paramLayoutInflater.inflate(R.layout.fragment_correct_exercise, paramViewGroup, false);
return view;
}
private VideoView mVideoView;
public void onStart() {
super.onStart();
if (!User.logout) {
this.ws.callSearchDialog(getActivity(), "조회중입니다.");
this.videoView = ((MyVideoView) getActivity().findViewById(R.id.videoView));
localCustomMediaController = new CustomMediaController(getActivity());
}
try {
this.videoView.setVideoPath(this.uri);
this.videoView.bringToFront();
this.videoView.setMediaController(localCustomMediaController);
this.videoView.requestFocus();
this.videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer paramAnonymousMediaPlayer) {
ExerciseFragment.this.videoView.seekTo(2);
ExerciseFragment.this.ws.removeSearchDialog();
}
});
} catch (Exception localException) {
localException.printStackTrace();
this.ws.removeSearchDialog();
}
ExerciseFragment.this.ws.removeSearchDialog();
}
public void onStop() {
super.onStop();
}
class CustomMediaController extends MediaController {
ImageButton mCCBtn;
Context mContext;
public CustomMediaController(Context context) {
super(context);
this.mContext = context;
}
private View makeCCView() {
this.mCCBtn = new ImageButton(this.mContext);
this.mCCBtn.setImageResource(R.drawable.icon_fullscreen_24);
this.mCCBtn.setBackgroundColor(0);
this.mCCBtn.setOnClickListener(new OnClickListener() {
public void onClick(View paramAnonymousView) {
paramAnonymousView = ExerciseFragment.this.videoView;
if (ExerciseFragment.this.videoView.isFull) { // isFull =
ExerciseFragment.this.videoView.isFull = false;
} else {
ExerciseFragment.this.videoView.isFull = true;
}
ExerciseFragment.this.videoView.requestLayout();
}
});
return this.mCCBtn;
}
public void setAnchorView(View paramView) {
super.setAnchorView(paramView);
FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
frameParams.gravity = Gravity.RIGHT | Gravity.TOP;
addView(makeCCView(), frameParams);
}
}
和.xml源
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_exercise"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<MyVideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
更新
这是MyVideoView.java
public class MyVideoView extends VideoView
{
public boolean isFull = false;
public MyVideoView(Context paramContext, AttributeSet paramAttributeSet)
{
super(paramContext, paramAttributeSet);
}
public void onMeasure(int paramInt1, int paramInt2)
{
if (this.isFull)
{
((WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
setMeasuredDimension(paramInt1, paramInt2);
return;
}
setMeasuredDimension(BaseActivity.displayWidth, BaseActivity.displayHeight/2);
}
}
是的,请有人帮助我。感谢