Created
June 3, 2015 21:08
-
-
Save r17171709/792d73ad229694433529 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//viewpager中同时包含image跟surfaceview的情况处理 | |
//给viewPager中的View添加id,便于后续查找 | |
for(int i=0;i<multi_media.size();i++) { | |
if (multi_media.get(i).gettype().endsWith("0")) { | |
ImageView imageView=new ImageView(this); | |
imageView.setImageResource(R.drawable.ic_launcher); | |
bitmapUtils.display(imageView, multi_media.get(i).getDescription_url(), config); | |
views.add(imageView); | |
} else { | |
LinearLayout linear=new LinearLayout(this); | |
linear.setGravity(Gravity.CENTER); | |
SurfaceView view=new SurfaceView(this); | |
view.setId(10000+i); | |
linear.addView(view);; | |
views.add(linear); | |
} | |
} | |
//viewPager中每次翻页执行操作 | |
viewPager.setOnPageChangeListener(new OnPageChangeListener() { | |
@Override | |
public void onPageSelected(int arg0) { | |
// TODO Auto-generated method stub | |
releaseMediaPlayer(); | |
doCleanUp(); | |
if(multi_media.get(arg0).gettype().endsWith("1")) { | |
switchPosition(arg0); | |
} | |
} | |
@Override | |
public void onPageScrolled(int arg0, float arg1, int arg2) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onPageScrollStateChanged(int arg0) { | |
// TODO Auto-generated method stub | |
} | |
}); | |
//播放操作 | |
private void switchPosition(int arg0) { | |
currentPosition=arg0; | |
SurfaceView mPreview=(SurfaceView) viewPager.findViewById(10000+arg0); | |
currentSurfaceView=mPreview; | |
holder = mPreview.getHolder(); | |
holder.addCallback(PlayerActivity.this); | |
holder.setFormat(PixelFormat.RGBA_8888); | |
playVideo(arg0); | |
} | |
//屏幕全屏方法 | |
@Override | |
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { | |
if (width == 0 || height == 0) { | |
Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")"); | |
return; | |
} | |
mIsVideoSizeKnown = true; | |
float scale=CommonUtils.getScale(width, height, screenWidth, screenHeight); | |
LayoutParams lp=currentSurfaceView.getLayoutParams(); | |
lp.width=(int)(scale*width); | |
lp.height=(int) (scale*height); | |
currentSurfaceView.setLayoutParams(lp); | |
mVideoWidth = width; | |
mVideoHeight = height; | |
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) { | |
startVideoPlayback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment