//布局
<RelativeLayout
android:layout_width="match_parent"android:layout_height="wrap_content"
android:background="#000000" >
<RelativeLayout
android:id="@+id/icon_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="200dip"
android:visibility="visible" >
<com.loopj.android.image.SmartImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="200dip"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:visibility="visible"
/>
<ImageView
android:id="@+id/play_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/newplay" />
<com.android.video.widget.VideoSuperPlayer
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="200dip"
android:layout_centerHorizontal="true"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
package com.qulian.bianzhen.activity;
import com.android.video.widget.MediaHelp;
import com.android.video.widget.VideoSuperPlayer;
import com.android.video.widget.VideoSuperPlayer.VideoPlayCallbackImpl;
import com.example.bianzhen.R;
import com.google.gson.Gson;
import com.loopj.android.image.SmartImageView;
import com.qulian.bianzhen.bean.DiseaseBean2;
import com.qulian.bianzhen.bean.DiseaseBean3;
import com.qulian.bianzhen.utils.MyUtils;
import com.qulian.bianzhen.utils.TimeUtils;
import com.qulian.util.HttpUtil1;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class ShipinActivity extends Activity {
private int id;
private String title;
private ImageButton imgbtn_left1;
private TextView txt_title;
private String infopl;
private Gson gson = new Gson();
private Context context;
private DiseaseBean3 diseaseBean1;
private VideoSuperPlayer mVideoViewLayout;
private ImageView mPlayBtnView;
private SmartImageView icon;
private boolean isPlaying;
private int indexPostion = -1;
private TextView tv_t2,tv_t3,tv_t4;
// tv_t1,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shipin);
id=getIntent().getIntExtra("id", 0);
title=getIntent().getStringExtra("title");
System.out.println("id"+id);
initView();
initData();
mPlayBtnView.setOnClickListener(new MyOnclick(mPlayBtnView, mVideoViewLayout));
}
class MyOnclick implements OnClickListener {
VideoSuperPlayer mSuperVideoPlayer;
ImageView mPlayBtnView;
public MyOnclick(ImageView mPlayBtnView,
VideoSuperPlayer mSuperVideoPlayer) {
this.mSuperVideoPlayer = mSuperVideoPlayer;
this.mPlayBtnView = mPlayBtnView;
}
@Override
public void onClick(View v) {
MediaHelp.release();
isPlaying = true;
mSuperVideoPlayer.setVisibility(View.VISIBLE);
mSuperVideoPlayer.loadAndPlay(MediaHelp.getInstance(),diseaseBean1.value.videourl, 0, false);
mSuperVideoPlayer.setVideoPlayCallback(new MyVideoPlayCallback(mPlayBtnView, mSuperVideoPlayer));
}
}
class MyVideoPlayCallback implements VideoPlayCallbackImpl {
ImageView mPlayBtnView;
VideoSuperPlayer mSuperVideoPlayer;
public MyVideoPlayCallback(ImageView mPlayBtnView,
VideoSuperPlayer mSuperVideoPlayer) {
this.mPlayBtnView = mPlayBtnView;
this.mSuperVideoPlayer = mSuperVideoPlayer;
}
@Override
public void onCloseVideo() {
closeVideo();
}
@Override
public void onSwitchPageType() {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
Intent intent = new Intent(new Intent(ShipinActivity.this,FullVideoActivity.class));
intent.putExtra("video", diseaseBean1.value.videourl);
intent.putExtra("position",mSuperVideoPlayer.getCurrentPosition());
startActivityForResult(intent, 1);
}
}
@Override
public void onPlayFinish() {
closeVideo();
}
private void closeVideo() {
isPlaying = false;
indexPostion = -1;
mSuperVideoPlayer.close();
MediaHelp.release();
mPlayBtnView.setVisibility(View.VISIBLE);
mSuperVideoPlayer.setVisibility(View.GONE);
}
}
/**
* 监听生命周期
*/
@Override
protected void onDestroy() {
MediaHelp.release();
super.onDestroy();
}
@Override
protected void onResume() {
MediaHelp.resume();
super.onResume();
}
@Override
protected void onPause() {
MediaHelp.pause();
super.onPause();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MediaHelp.getInstance().seekTo(data.getIntExtra("position", 0));
}
private void initData() {
new Thread() {
public void run() {
try {
infopl = HttpUtil1.getData("http://www.lantisoft.com/v/vinfo.php?id="+id);
System.out.println(infopl);
if (infopl!=null) {
parseJson(infopl);// 解析,展示
}else {
MyUtils.showToast(ShipinActivity.this, "请检查网络连接");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
/**
* 解析json字符串
*
* @param jsonString
*/
private void parseJson(String jsonString) {
diseaseBean1 = gson.fromJson(infopl, DiseaseBean3.class);
System.out.println(diseaseBean1.value.id);
runOnUiThread(new Runnable() {
@Override
public void run() {
icon.setImageUrl(diseaseBean1.value.litpic);
// tv_t1.setText(TimeUtils.formatTime(Long.parseLong(diseaseBean1.value.pubdate)*1000L));
tv_t2.setText(diseaseBean1.value.writer);
tv_t3.setText(diseaseBean1.value.title);
tv_t4.setText(diseaseBean1.value.description);
}
});
}
private void initView() {
// tv_t1=(TextView) findViewById(R.id.tv_t1);
tv_t2=(TextView) findViewById(R.id.tv_t2);
tv_t3=(TextView) findViewById(R.id.tv_t3);
tv_t4=(TextView) findViewById(R.id.tv_t4);
mVideoViewLayout = (VideoSuperPlayer) findViewById(R.id.video);
mPlayBtnView = (ImageView) findViewById(R.id.play_btn);
icon = (SmartImageView) findViewById(R.id.icon);
txt_title = (TextView) findViewById(R.id.txt_title);
txt_title.setText(title);
imgbtn_left1 = (ImageButton) findViewById(R.id.imgbtn_left1);
imgbtn_left1.setBackgroundResource(R.drawable.fanhui);
imgbtn_left1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
finish();
}
});
}
}
<activity
android:name="com.qulian.bianzhen.activity.ShipinActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
></activity>
<activity
android:name="com.qulian.bianzhen.activity.FullVideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
package com.qulian.bianzhen.activity;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import com.android.video.widget.MediaHelp;
import com.android.video.widget.VideoMediaController;
import com.android.video.widget.VideoSuperPlayer;
import com.android.video.widget.VideoSuperPlayer.VideoPlayCallbackImpl;
import com.example.bianzhen.R;
/**
* 满屏界面
*
* @author chenzf
* @e-mail seven2729@126.com
* @version v1.0
* @copyright 2010-2015
* @create-time 2016年3月21日15:05:26
*
*/
public class FullVideoActivity extends Activity {
private VideoSuperPlayer mVideo;
private String info;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 横屏
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_full);
mVideo = (VideoSuperPlayer) findViewById(R.id.video);
info = getIntent().getStringExtra("video");
mVideo.loadAndPlay(MediaHelp.getInstance(),info, getIntent()
.getExtras().getInt("position"), true);
mVideo.setPageType(VideoMediaController.PageType.EXPAND);
mVideo.setVideoPlayCallback(new VideoPlayCallbackImpl() {
@Override
public void onSwitchPageType() {
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
finish();
}
}
@Override
public void onPlayFinish() {
finish();
}
@Override
public void onCloseVideo() {
finish();
}
});
}
@Override
public void finish() {
Intent intent = new Intent();
intent.putExtra("position", mVideo.getCurrentPosition());
setResult(RESULT_OK, intent);
super.finish();
}
@Override
protected void onPause() {
super.onPause();
MediaHelp.pause();
}
@Override
protected void onResume() {
super.onResume();
MediaHelp.resume();
}
}