@Override public void onSuccess(String response) { Log.d(TAG, "the response --> " + response); Movie movie = MJsonUtil.gson.fromJson(response, new TypeToken<Movie>() {}.getType()); if (movie.getErrorCode() == 0) { mCurrentMovieDetail = movie; videoUri = movie.getData().getFilmUrl(); String title = movie.getData().getMovieName(); Log.d(TAG, "reponse video url: " + videoUri + " the name -->> " + title); mVideoView.setVideoURI(Uri.parse(videoUri), title); mVideoView.requestFocus(); // updateShareTVdatabase(movie, // mVideoView.getCurrentPosition()); int mPostion = getIntent().getIntExtra(Constants.MovieExtra.EXTRA_MOVIE_POSTION, 0); Log.d(TAG, "mPostion: " + mPostion); mVideoView.seekTo(mPostion); mVideoView.start(); // 需要更新底部的Fragment的信息 if (mNeedShowChildFragmentLater) { mNeedShowChildFragmentLater = false; Log.d(TAG, "show child fragment later"); showChildFragment(mRadioGroup.getCheckedRadioButtonId()); } } else { Log.d(TAG, movie.getErrorMsg()); } }
@Override protected void onPause() { mVideoView.pause(); updateShareTVdatabase(mCurrentMovieDetail, mVideoView.getCurrentPosition()); Log.d(TAG, "mVideoView.getCurrentPosition():" + mVideoView.getCurrentPosition()); Log.d(TAG, "moveid:" + mCurrentMovieDetail.getData().getMovieId()); super.onPause(); }
public void onNewMoviePathSet(String path) { Log.i(TAG, "path : " + path); mVideoView.setVideoPath(path); // mVideoView.setVideoURI(Uri.parse(path)); videoUri = path; mVideoView.requestFocus(); // updateShareTVdatabase(videoUri, // mVideoView.getCurrentPosition()); // mVideoView.start(); int postion = 0; Log.d(TAG, "mPostion: " + postion); mVideoView.seekTo(postion); mVideoView.start(); }
public void setScreenOrientation(boolean isFullScreen, int screenOritation) { DisplayMetrics metrics = getResources().getDisplayMetrics(); if (isFullScreen) { Log.i("jiangtao4", "activity onToggleFullScreen"); video_down_layout.setVisibility(View.GONE); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); mVideoView.setLayoutParams(layoutParams); width = metrics.widthPixels; height = metrics.heightPixels; mVideoView.setDimensions(height, width); } else { video_down_layout.setVisibility(View.VISIBLE); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 200); mVideoView.setLayoutParams(layoutParams); // 屏幕旋转后,宽高相反 height = (int) (metrics.widthPixels * (3 / (8 * 1.0f))); width = metrics.heightPixels; mVideoView.setDimensions(width, height); } mVideoView.setIsFullScreen(isFullScreen); setRequestedOrientation(screenOritation); }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // calculateVideoViewSize(); // mVideoView.setDimensions(width, height); // mVideoView.getHolder().setFixedSize(width, height); Log.i(TAG, " == onConfigurationChanged"); String screen = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ? "横屏" : "竖屏"; Toast.makeText(this, screen, Toast.LENGTH_LONG).show(); bar.refreshDrawableState(); }
private void updateFavState(String uri, boolean isSelected) { // TODO Auto-generated method stub Cursor mCursor = null; SQLiteDatabase db = null; try { Log.d("renjun1", "111111111"); db = dbHelper.getWritableDatabase(); mCursor = db.query( "play_history", new String[] {"_id,_uri"}, "_uri=?", new String[] {videoUri}, null, null, null); ContentValues values = new ContentValues(); Log.d("renjun1", "uri " + uri); values.put("_uri", videoUri); values.put("_fav", isSelected ? 1 : 0); if (mCursor == null || mCursor.getCount() == 0) { Log.d("renjun1", "22222222"); dbHelper.insert(values); } else { Log.d("renjun1", "3333333333"); dbHelper.update(values, uri); } } finally { if (mCursor != null) { mCursor.close(); } if (db != null) { db.close(); } } }
@Override public void onError(VolleyError error) { super.onError(error); Log.d(TAG, "the response --> " + error.toString()); showToast("网络连接错误,无法播放!"); /* * mVideoView.setVideoURI(Uri.parse( * "http://fx.72zhe.com/static/fx/sample.mp4")); videoUri = * "http://fx.72zhe.com/static/fx/sample.mp4"; */ // mVideoView.requestFocus(); // updateShareTVdatabase(videoUri, mVideoView.getCurrentPosition()); // mVideoView.start(); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.i("jiangtao4", "activity keydown"); if (keyCode == KeyEvent.KEYCODE_BACK) { Configuration config = getResources().getConfiguration(); DisplayMetrics metrics = getResources().getDisplayMetrics(); // if the screen orientation is landscape now if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { // set it portait!!! setScreenOrientation(false, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); return true; } else { updateShareTVdatabase(mCurrentMovieDetail, mVideoView.getCurrentPosition()); return super.onKeyDown(keyCode, event); } } return super.onKeyDown(keyCode, event); }
private void updateShareTVdatabase(Movie movie, int postion) { // TODO Auto-generated method stub Cursor mCursor = null; SQLiteDatabase db = null; try { Log.d("renjun1", "111111111"); // SQLiteDatabase db = dbHelper.getWritableDatabase(); db = dbHelper.getWritableDatabase(); mCursor = db.query( FlyShareTVdataHelper.TBL_HISTORY_VIDEOS, new String[] {"_id,_uri"}, "_id=?", new String[] {movie.getData().getMovieId()}, null, null, null); ContentValues values = new ContentValues(); String nowTime = getCurrentTime(); String filename = movie.getData().getMovieName(); String thumb = movie.getData().getThumb(); Log.d("renjun1", "filename:" + filename); Log.d("renjun1", "videoUri " + videoUri); Log.d("renjun1", "nowTime " + nowTime); Log.d("renjun1", "postion:" + postion); values.put("_uri", movie.getData().getFilmUrl()); values.put("_id", movie.getData().getMovieId()); values.put("_time", nowTime); values.put("_pos", postion); values.put("_name", filename); values.put("_thumb", thumb); if (mCursor == null || mCursor.getCount() == 0) { Log.d("renjun1", "22222222"); dbHelper.insert(values); } else { Log.d("renjun1", "3333333333"); dbHelper.update(values, movie.getData().getMovieId()); } } finally { if (mCursor != null) { mCursor.close(); } if (db != null) { db.close(); } } }
@Override public void onClick(View arg0) { // TODO Auto-generated method stub Log.d("renjun1", "download 11111111111"); // DownloadVideoManager mDmger = new DownloadVideoManager(context); VideoItem vitem = new VideoItem(); vitem.setVideoUri(videoUri); /* * Intent intent = new Intent(); //intent.setClass(context, * DownloadManagerService.class); intent.setClass(context, * OwnerMsgActivity.class); * intent.setAction("shareTv_download_progress"); Bundle bud = new * Bundle(); bud.putSerializable("videoRes", vitem); * intent.putExtras(bud); startActivity(intent); */ // mBinder.addVideoToDownQuee(vitem); // vitem.setVideoUri(videoUri); // mDmger.setRemotePath(videoUri); // mDmger.addVideoToDownQuee(vitem); }
/** 注意,在这里统一所有的按钮点击处理!!! */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.image_share: Log.d(TAG, "share...."); showShare(); break; case R.id.image_download: Log.d(TAG, "download...."); ToastUtils.ToastAdd(getContext(), "已加入下载队列"); VideoItem vitem = new VideoItem(); vitem.setVideoUri(mCurrentMovieDetail.getData().getFilmUrl()); vitem.setfileName(mCurrentMovieDetail.getData().getMovieName()); vitem.setMoveId(mCurrentMovieDetail.getData().getMovieId()); Log.d("renjun3", "moveiddetail: " + mCurrentMovieDetail.getData().getMovieId()); // DownloadVideoManager mDmger = new DownloadVideoManager(getApplication()); // mDmger.addVideoToDownQuee(vitem); Intent intent = new Intent(); intent.setClass(context, DownloadManagerService.class); intent.setAction("cn.fxdata.tv.download_action"); Bundle bud = new Bundle(); bud.putSerializable("videoRes", vitem); intent.putExtras(bud); startService(intent); // mBinder.addVideoToDownQuee(vitem); // vitem.setVideoUri(videoUri); // mDmger.setRemotePath(videoUri); // break; case R.id.image_fav: Log.d(TAG, "favorate...."); if (isSelected) { isSelected = false; if (mCurrentMovieDetail != null) { FavDbUtil.getInstance(getContext()).removeFavVideo(movieId); ToastUtils.ToastAdd(getContext(), "取消收藏"); image_fav.setImageResource(R.drawable.vedio_fav_normal); } } else { isSelected = true; String movieIdString = movieId; if (mCurrentMovieDetail.getData() != null && movieIdString != null) { String movieName = mCurrentMovieDetail.getData().getMovieName(); String movieTime = mCurrentMovieDetail.getData().getReleaseTime() == null ? "" : mCurrentMovieDetail.getData().getReleaseTime(); // 获得影片的缩略图url,方便加载 String movieImageUrl = mCurrentMovieDetail.getData().getFilmUrl(); String praiseTimeString = "1212"; if (movieName != null) { FavDbUtil.getInstance(getContext()) .addUpdateFavVideo( movieIdString, movieName, movieTime, praiseTimeString, movieImageUrl); ToastUtils.ToastAdd(getContext(), "收藏成功"); image_fav.setImageResource(R.drawable.vedio_fav_pressed); } else { ToastUtils.ToastAdd(getContext(), "电影名称为空,无法收藏"); } } else { ToastUtils.ToastAdd(getContext(), "电影数据为空,无法收藏"); } } break; } }
@Override public void onCancel() { super.onCancel(); Log.d(TAG, "cancelled"); }
private String getNamefromUri(String Uri) { // TODO Auto-generated method stub String mName = Uri.substring(Uri.lastIndexOf("/") + 1); Log.d("renjun1", "mName: " + mName); return mName.substring(0, mName.lastIndexOf(".")); }
@Override public void onDestroy() { super.onDestroy(); Log.d("renjun1", "activity destory 1111"); // unbindService(conn); }
@SuppressLint("LongLogTag") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = this; setContentView(R.layout.act_video_play_view_detail); // 拿到数据库实例 dbHelper = new FlyShareTVdataHelper(this); initFragments(); initView(); Intent intent = new Intent(this, DownloadManagerService.class); // intent.setAction("cn.fxdata.tv.download_action"); // startService(intent); // bindService(intent,conn,0); mVideoView.setOnToggleFullScreen(this); mVideoView.setBackClickInterface(this); mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { bar.setVisibility(View.GONE); } }); calculateVideoViewSize(); mVideoView.setDimensions(width, height); videoControllerView = new cn.fxdata.tv.view.video.VideoControllerView(this); mVideoView.setMediaController(videoControllerView); videoUri = null; if (getIntent().getExtras() == null) { ToastUtils.ToastAdd(getContext(), "数据为空"); mVideoView.setVideoURI(Uri.parse("http://fx.72zhe.com/static/fx/sample.mp4")); videoUri = "http://fx.72zhe.com/static/fx/sample.mp4"; } else if (getIntent().hasExtra(Constants.MovieExtra.EXTRA_MOVIE_PATH)) { if (getIntent().hasExtra(Constants.MovieExtra.EXTRA_MOVIE_ID)) { movieId = getIntent().getExtras().getString(Constants.MovieExtra.EXTRA_MOVIE_ID); Log.d(TAG, "forplay video movieID: " + movieId); VolleyTools tools = VolleyTools.getInstance(this.getContext()); tools.addToRequestQueue( new StringRequest( Method.GET, Constants.ServerConfig.MOVIE_DETAIL_URL + "&movie_id=" + movieId, getMovieDetailListener), tools.VolleyTAG); // 判断是否是收藏的视频,显示不同的收藏状态图片 boolean isFav = FavDbUtil.getInstance(getContext()).isFavVideo(movieId); isSelected = isFav; Log.d(TAG, "The fav video is -->> " + isFav); if (isFav) { image_fav.setImageResource(R.drawable.vedio_fav_pressed); } else { image_fav.setImageResource(R.drawable.vedio_fav_normal); } } else { String path = getIntent().getExtras().getString(Constants.MovieExtra.EXTRA_MOVIE_PATH); Log.i(TAG, "path : " + path); mVideoView.setVideoURI(Uri.parse(path)); videoUri = path; mVideoView.requestFocus(); // updateShareTVdatabase(videoUri, // mVideoView.getCurrentPosition()); // mVideoView.start(); int mPostion = getIntent().getIntExtra(Constants.MovieExtra.EXTRA_MOVIE_POSTION, 0); Log.d(TAG, "mPostion: " + mPostion); mVideoView.seekTo(mPostion); mVideoView.start(); } if (getIntent().hasExtra(Constants.MovieExtra.EXTRA_MOVIE_THUMB)) { mMovieThumb = getIntent().getExtras().getString(Constants.MovieExtra.EXTRA_MOVIE_THUMB); } } else if (getIntent().hasExtra(Constants.MovieExtra.EXTRA_MOVIE_ID)) { movieId = getIntent().getExtras().getString(Constants.MovieExtra.EXTRA_MOVIE_ID); Log.d(TAG, "forplay video movieID: " + movieId); VolleyTools tools = VolleyTools.getInstance(this.getContext()); tools.addToRequestQueue( new StringRequest( Method.GET, Constants.ServerConfig.MOVIE_DETAIL_URL + "&movie_id=" + movieId, getMovieDetailListener), tools.VolleyTAG); // 判断是否是收藏的视频,显示不同的收藏状态图片 boolean isFav = FavDbUtil.getInstance(getContext()).isFavVideo(movieId); isSelected = isFav; Log.d(TAG, "The fav video is -->> " + isFav); if (isFav) { image_fav.setImageResource(R.drawable.vedio_fav_pressed); } else { image_fav.setImageResource(R.drawable.vedio_fav_normal); } } else { ToastUtils.ToastAdd(getContext(), "视频播放地址为空"); /* * mVideoView.setVideoURI(Uri.parse( * "http://fx.72zhe.com/static/fx/sample.mp4")); videoUri = * "http://fx.72zhe.com/static/fx/sample.mp4"; * * mVideoView.requestFocus(); updateShareTVdatabase(videoUri, * mVideoView.getCurrentPosition()); mVideoView.start(); */ } }