我有一个viewflipper,其中有视频和图像。第一次运行时一切正常。显示最后一个孩子并重复查看后,视频不播放,黑屏全部保留时间。 提前谢谢。
我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.kiosk_mode);
mSelectedPressoId=PreferenceConnector.readString(KioskModeActivity.this, PreferenceConnector.SELECTED_PRESSO_ID, "");
bindControl();
fetchSlidesFromDb();
}
public void bindControl(){
mFlipper=(ViewFlipper)findViewById(R.id.viewflipper);
mParentView=(FrameLayout)findViewById(R.id.parent_background);
mKioskModeIcon=(ImageView)findViewById(R.id.kiosk_mode_icon);
mExitBar=(LinearLayout)findViewById(R.id.exit_bar);
detector = new GestureDetector(new SwipeGestureDetector());
mCounter=new MyCounter(10000, 1000);
mActivePointers = new SparseArray<PointF>();
mKioskModeIcon.setOnClickListener(this);
mHomeIcon=(ImageView)findViewById(R.id.homeIcon);
mHomeIcon.setOnClickListener(this);
mCommonMethod=new CommonMethod(getApplicationContext());
position=new ArrayList<String>();
mTransitionTime=PreferenceConnector.readString(getApplicationContext(), PreferenceConnector.TRANSITION_TIME, "");
Log.v("transition time from prefrence isss",mTransitionTime+">>>");
if(mTransitionTime.equalsIgnoreCase("")){
mFlipper.setFlipInterval(10000);
}else{
int mTransitionTimeInMills=Integer.parseInt(mTransitionTime)*1000;
mFlipper.setFlipInterval(mTransitionTimeInMills);
}
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(
getBaseContext(), R.anim.push_left_out));
mFlipper.setInAnimation(AnimationUtils.loadAnimation(
getBaseContext(), R.anim.push_left_in));
mFlipper.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {
Log.d("new view is ",">>>>>>>>>>>>>>>");
}
public void onAnimationEnd(Animation animation) {
mVideoPosition=mFlipper.getDisplayedChild();
Log.d("new view is flipped",mVideoPosition+">>>>>>>>>>>>>>>"+mPressoPathList.get(mVideoPosition));
if(mSlideTypeList.get(mVideoPosition).equalsIgnoreCase("video")){
Log.d("onside iffffff",myVideoView+">>>>>");
myVideoView.start();
}
}
});
mFlipper.startFlipping();
mFlipper.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
detector.onTouchEvent(event);
return true;
}
});
}
public void fetchSlidesFromDb(){
PresentationDatabase databaseClass = new PresentationDatabase(getApplicationContext(), DatabaseUtil.PresenationTable.DATABASE_NAME, null, DatabaseUtil.PresenationTable.DATABASE_VERSION);
SQLiteDatabase db = databaseClass.getReadableDatabase();
mPressoPathList=new ArrayList<String>();
mSlideTypeList=new ArrayList<String>();
String where = DatabaseUtil.PresenationTable.PRESENTATION_ID + "="
+"'"+mSelectedPressoId+"'";
Cursor mCursor=db.query(DatabaseUtil.PresenationTable.TABLE_NAME, null, where,
null, null, null, null);
Log.e("cursor size isssssss",mCursor.getCount()+">>");
if(mCursor.getCount()>0){
mCursor.moveToFirst();
do{
String slide_content_path=mCursor.getString(mCursor.getColumnIndex(DatabaseUtil.PresenationTable.CONTENT_LOCAL_PATH));
String mSlideType=mCursor.getString(mCursor.getColumnIndex(DatabaseUtil.PresenationTable.SLIDE_TYPE));
if(!mSlideType.equalsIgnoreCase("pdf")){
mPressoPathList.add(slide_content_path);
mSlideTypeList.add(mSlideType);
}
}while(mCursor.moveToNext());
}
Log.d("slide path issssssss",mPressoPathList+"");
setFlipperImage(mSlideTypeList, mPressoPathList);
mCursor.close();
db.close();
}
//create view to be put in view flipper
private void setFlipperImage(ArrayList<String>mSlideType,ArrayList<String>mSlidePath) {
int size=mSlideType.size();
for(int i=0;i<size;i++){
if(mSlideType.get(i).equalsIgnoreCase("image")){
ImageView image = new ImageView(getApplicationContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
image.setLayoutParams(layoutParams);
image.setScaleType(ScaleType.FIT_XY);
//image.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 2;
bmp = BitmapFactory.decodeFile(mSlidePath.get(i),options);
image.setImageBitmap(bmp);
image.setTag(i);
position.add(i+"");
mFlipper.addView(image);
}else{
myVideoView = new VideoView(this);
myVideoView.setVideoPath(mSlidePath.get(i));
Log.e("my video path isssss",mSlidePath.get(i));
myVideoView.requestFocus();
myVideoView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// l.setBackgroundColor(Color.BLACK);
myVideoView.setKeepScreenOn(true);
mFlipper.addView(myVideoView);
myVideoView.start();
myVideoView.seekTo(500);
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mFlipper.stopFlipping();
}
});
myVideoView.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
Log.d("inside oncomplete listner",">>>>>");
myVideoView.stopPlayback();
mVideoPosition=mVideoPosition+1;
mFlipper.setDisplayedChild(mVideoPosition);
mFlipper.startFlipping();
myVideoView.seekTo(500);
}
});
}
//
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
//do nothing*
}
答案 0 :(得分:1)
我通过添加
解决了这个问题myVideoView.start();
进入事件监听器
myVideoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mFlipper.stopFlipping();
myVideoView.start();
}
});