package com.zh_weir.videoplayer;
import java.io.File;
import java.io.FileFilter;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedList;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import com.admob.android.ads.AdView;
import com.zh_weir.videoplayer.SoundView.OnVolumeChangedListener;
import com.zh_weir.videoplayer.VideoView.MySizeChangeLinstener;
import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue.IdleHandler;
import android.provider.MediaStore;
import android.text.AndroidCharacter;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AnalogClock;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
public class VideoPlayerActivity extends Activity {
private final static String TAG = "VideoPlayerActivity";
private boolean isOnline = false;
private boolean isChangedVideo = false;
public static LinkedList<MovieInfo> playList = new LinkedList<MovieInfo>();
public class MovieInfo{
String displayName;
String path;
}
private Uri videoListUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
private static int position ;
private static boolean backFromAD = false;
private int playedTime;
private AdView adView;
private VideoView vv = null;
private SeekBar seekBar = null;
private TextView durationTextView = null;
private TextView playedTextView = null;
private GestureDetector mGestureDetector = null;
private AudioManager mAudioManager = null;
private int maxVolume = 0;
private int currentVolume = 0;
private ImageButton bn1 = null;
private ImageButton bn2 = null;
private ImageButton bn3 = null;
private ImageButton bn4 = null;
private ImageButton bn5 = null;
private View controlView = null;
private PopupWindow controler = null;
private SoundView mSoundView = null;
private PopupWindow mSoundWindow = null;
private View extralView = null;
private PopupWindow extralWindow = null;
private static int screenWidth = 0;
private static int screenHeight = 0;
private static int controlHeight = 0;
private final static int TIME = 6868;
private boolean isControllerShow = true;
private boolean isPaused = false;
private boolean isFullScreen = false;
private boolean isSilent = false;
private boolean isSoundShow = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("OnCreate", getIntent().toString());
Looper.myQueue().addIdleHandler(new IdleHandler(){
@Override
public boolean queueIdle() {
// TODO Auto-generated method stub
if(controler != null && vv.isShown()){
controler.showAtLocation(vv, Gravity.BOTTOM, 0, 0);
//controler.update(screenWidth, controlHeight);
controler.update(0, 0, screenWidth, controlHeight);
}
if(extralWindow != null && vv.isShown()){
extralWindow.showAtLocation(vv,Gravity.TOP,0, 0);
extralWindow.update(0, 25, screenWidth, 60);
}
//myHandler.sendEmptyMessageDelayed(HIDE_CONTROLER, TIME);
return false;
}
});
controlView = getLayoutInflater().inflate(R.layout.controler, null);
controler = new PopupWindow(controlView);
durationTextView = (TextView) controlView.findViewById(R.id.duration);
playedTextView = (TextView) controlView.findViewById(R.id.has_played);
mSoundView = new SoundView(this);
mSoundView.setOnVolumeChangeListener(new OnVolumeChangedListener(){
@Override
public void setYourVolume(int index) {
cancelDelayHide();
updateVolume(index);
hideControllerDelay();
}
});
mSoundWindow = new PopupWindow(mSoundView);
extralView = getLayoutInflater().inflate(R.layout.extral, null);
extralWindow = new PopupWindow(extralView);
ImageButton backButton = (ImageButton) extralView.findViewById(R.id.back);
ImageButton aboutButton = (ImageButton) extralView.findViewById(R.id.about);
position = -1;
backButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
VideoPlayerActivity.this.finish();
}
});
aboutButton.setOnClickListener(new OnClickListener(){
Dialog dialog;
OnClickListener mClickListener = new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("DIALOG", "DISMISS");
dialog.dismiss();
//vv.seekTo(msec);
vv.start();
}
};
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/*Intent intent = new Intent();
intent.setClass(VideoPlayerActivity.this, VideoChooseActivity.class);
VideoPlayerActivity.this.startActivityForResult(intent, 0);*/
dialog = new Dialog(VideoPlayerActivity.this, R.style.transDialog);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
View view = VideoPlayerActivity.this.getLayoutInflater().inflate(R.layout.about, null);
dialog.setContentView(view);
view.findViewById(R.id.cancel).setOnClickListener(mClickListener);
vv.pause();
dialog.show();
cancelDelayHide();
}
});
bn1 = (ImageButton) controlView.findViewById(R.id.button1);
bn2 = (ImageButton) controlView.findViewById(R.id.button2);
bn3 = (ImageButton) controlView.findViewById(R.id.button3);
bn4 = (ImageButton) controlView.findViewById(R.id.button4);
bn5 = (ImageButton) controlView.findViewById(R.id.button5);
vv = (VideoView) findViewById(R.id.vv);
vv.setOnErrorListener(new OnErrorListener(){
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
vv.stopPlayback();
isOnline = false;
new AlertDialog.Builder(VideoPlayerActivity.this)
.setTitle("对不起")
.setMessage("您所播的视频格式不正确,播放已停止。")
.setPositiveButton("知道了",
new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
vv.stopPlayback();
}
})
.setCancelable(false)
.show();
return false;
}
});
Uri uri = getIntent().getData();
if(uri!=null){
vv.stopPlayback();