@OnClick(R.id.watch_trailer) public void openTrailer(View v) { Intent trailerIntent = new Intent(mActivity, TrailerPlayerActivity.class); if (!YouTubeData.isYouTubeUrl(sMovie.trailer)) { trailerIntent = new Intent(mActivity, VideoPlayerActivity.class); } trailerIntent.putExtra(TrailerPlayerActivity.DATA, sMovie); trailerIntent.putExtra(TrailerPlayerActivity.LOCATION, sMovie.trailer); startActivity(trailerIntent); }
@Override protected Uri doInBackground(String... params) { String uriStr = null; String quality = "17"; // 3gpp medium quality, which should be fast enough to view over EDGE connection String videoId = params[0]; if (isCancelled()) return null; try { WifiManager wifiManager = (WifiManager) TrailerPlayerActivity.this.getSystemService(Context.WIFI_SERVICE); TelephonyManager telephonyManager = (TelephonyManager) TrailerPlayerActivity.this.getSystemService(Context.TELEPHONY_SERVICE); // if we have a fast connection (wifi or 3g), then we'll get a high quality YouTube video if (wifiManager.isWifiEnabled() && wifiManager.getConnectionInfo() != null && wifiManager.getConnectionInfo().getIpAddress() != 0) { quality = "22"; } else if (telephonyManager.getDataState() == TelephonyManager.DATA_CONNECTED && (telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSUPA || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSPA || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_HSDPA || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_EVDO_0 || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_EVDO_A)) { quality = "18"; } if (isCancelled()) return null; //////////////////////////////////// // calculate the actual URL of the video, encoded with proper YouTube token uriStr = YouTubeData.calculateYouTubeUrl(quality, true, videoId); if (isCancelled()) return null; } catch (Exception e) { Log.e( this.getClass().getSimpleName(), "Error occurred while retrieving information from YouTube.", e); } if (uriStr != null) { return Uri.parse(uriStr); } else { return null; } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.activity_videoplayer); mMedia = getIntent().getParcelableExtra(DATA); mMedia.title += " " + getString(R.string.trailer); String youTubeUrl = getIntent().getStringExtra(LOCATION); mStreamInfo = new StreamInfo(mMedia, null, null, null, null, youTubeUrl); mVideoPlayerFragment = (VideoPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.video_fragment); mVideoPlayerFragment.enableSubsButton(false); QueryYouTubeTask youTubeTask = new QueryYouTubeTask(); youTubeTask.execute(YouTubeData.getYouTubeVideoId(youTubeUrl)); }