@Override
  public void onFullscreen(boolean fullscreen) {
    viewContainer.setEnablePadding(!fullscreen);

    ViewGroup.LayoutParams playerParams = playerFragment.getView().getLayoutParams();
    if (fullscreen) {
      playerParams.width = MATCH_PARENT;
      playerParams.height = MATCH_PARENT;
    } else {
      playerParams.width = 0;
      playerParams.height = WRAP_CONTENT;
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.youtube_playerview);
    youtubeVideoID = getIntent().getStringExtra(YOUTUBE_VIDEO_ID);
    viewContainer = (ActionBarPaddedFrameLayout) findViewById(R.id.view_container);
    playerFragment =
        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
    playerFragment.initialize(Constants.YOUTUBE_DEVELOPER_KEY, this);
    viewContainer.setActionBar(getActionBar());

    // Action bar background is transparent by default.
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar()
        .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primary)));
  }
  @Override
  protected void onDisplay(Bundle savedInstanceState, PluginController controller) {

    // Get and cast the controller and model
    mController = (EdXController) controller;
    mModel = (EdXModel) controller.getModel();

    setContentView(R.layout.edx_study_room);

    YouTubePlayerFragment youTubePlayerFragment =
        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.edx_youtube_fragment);
    youTubePlayerFragment.initialize("AIzaSyAcYTsAuAhbb9zcd9z9u7mS8Z0_wrNoTUs", this);

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wl =
        pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "DoNotDimScreen");

    TextView discussionView = (TextView) findViewById(R.id.edx_sr_discussion);
    // discussionView.setMovementMethod(new ScrollingMovementMethod());
    discussionView.setMovementMethod(LinkMovementMethod.getInstance());

    // TextView vidDescView = (TextView) findViewById(R.id.edx_sr_video_desc);
    // vidDescView.setMovementMethod(LinkMovementMethod.getInstance());

    /*

          SurfaceView surfaceView = (SurfaceView) findViewById(R.id.edx_sr_surfaceview);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();


    getWindow().setFormat(PixelFormat.UNKNOWN);
    surfaceHolder.addCallback(new SurfaceHolder.Callback() {
    	public void surfaceDestroyed(SurfaceHolder holder) {
    	}
    	public void surfaceCreated(SurfaceHolder holder) {
    	}
    	public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    	}
    });
    // surfaceHolder.setFixedSize(176, 144);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mediaPlayer = new MediaPlayer();

    mediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
    	public void onBufferingUpdate(MediaPlayer mp, int percent) {
    		System.out.println("percent=" + percent);
    	}
    });



    mediaPlayer.setOnSeekCompleteListener(new  OnSeekCompleteListener() {
    	public void onSeekComplete(MediaPlayer mp) {
            SeekBar seekBar = (SeekBar) findViewById(R.id.edx_sr_seekbar);
    		seekBar.setMax(mediaPlayer.getDuration());
    		seekBar.setProgress(mediaPlayer.getCurrentPosition());
    	}
    });




    progBarUpdater = new UIUpdater(new Runnable() {
    	public void run() {
    		if(mediaPlayer.isPlaying()) {
    	        SeekBar seekBar = (SeekBar) findViewById(R.id.edx_sr_seekbar);
    	        seekBar.setMax(mediaPlayer.getDuration());
    	        seekBar.setProgress(mediaPlayer.getCurrentPosition());
    		}
    	}
    }, 1000);





    //Log.i("ON DISPLAY", "" + surfaceView);

    // make it 16:9 aspect ratio
    //Log.i("BALLOUTA", "" + surfaceView);
    //Log.i("BALLOUTA", "" + surfaceView.getViewTreeObserver());
    surfaceView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    	public void onGlobalLayout() {
    		SurfaceView surfaceView = (SurfaceView) findViewById(R.id.edx_sr_surfaceview);
    		int width = Math.min(surfaceView.getWidth(), surfaceView.getHeight() * 16 / 9);
    		int height = Math.min(surfaceView.getHeight(), surfaceView.getWidth() * 9 / 16);
    		surfaceView.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    		surfaceView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    	}
    });

    */

    attachButtonActions();
    attachSeekBarActions();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    // set playing video to -1, to check if a search ever occurred
    playingVideoIndex = -1;

    // accessing our player fragment through the contentView
    // setting up the youtube player through the playerFragment
    playerFragment =
        (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.search_player_fragment);

    // accessing our private developerKey.properties folder to hide our personal developer keys
    // this is so our dev keys will not be hosted on github
    // place a developerKey.properties file in your assets folder with a webBrowserKey and
    // androidKey
    // values if you want this to work
    try {
      AssetManager assetManager = getAssets();
      Properties prop = new Properties();
      String propFileName = "developerKey.properties";
      InputStream inputStream = assetManager.open(propFileName);
      if (inputStream != null) {
        prop.load(inputStream);
        inputStream.close();
        webKey = prop.getProperty("webBrowserKey");
        androidKey = prop.getProperty("androidKey");
      } else {
        throw new FileNotFoundException(
            "property file '" + propFileName + "'not found in the classpath");
      }
    } catch (Exception e) {
      System.out.println("Exception: " + e);
    }

    // only initialize our youTubePlayerFragment if our androidKey was obtained
    if (androidKey != null) {
      playerFragment.initialize(androidKey, this);
    } else {
      Log.d("Android Key: ", "failed to initialize");
    }

    // Accessing all of our components
    final Button searchButton =
        (Button) findViewById(R.id.search_button); // button to get YouTube search results
    final EditText songEditText =
        (EditText) findViewById(R.id.song_text); // editText for getting song from user
    final EditText artistEditText =
        (EditText) findViewById(R.id.artist_text); // editText for getting artist from user
    final ListView searchListView =
        (ListView) findViewById(R.id.search_list_view); // listView to show search results
    final FloatingActionButton returnButton =
        (FloatingActionButton)
            findViewById(R.id.return_button); // upload button to send song to host

    // input method manager to control when the keyboard is active
    final InputMethodManager inputManager =
        (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // if the user says they are done editing, search for results
    artistEditText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView textView, int actionID, KeyEvent keyEvent) {
            if (actionID == EditorInfo.IME_ACTION_DONE) {
              searchButton.performClick();
              inputManager.hideSoftInputFromWindow(
                  getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
              return true;
            }
            return false;
          }
        });

    // the YouTube search functionality
    searchButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            // tast for thread, so we can access networks outside of the main thread
            Runnable searchTask =
                new Runnable() {
                  @Override
                  public void run() {
                    // concatenate the artist and song names from the user
                    // NOTE: Maybe not have it be two things. Unnecessary but might look better?
                    String query =
                        artistEditText.getText().toString()
                            + " "
                            + songEditText.getText().toString();

                    // this synchronized lock ensures we don't display the search results until they
                    // are found
                    synchronized (lock) {
                      // only search for results if a webKey was obtained from .properties file
                      if (webKey != null) {
                        // calling our search function to access YouTube's api and return the search
                        // results
                        searchResults = Search.Search(query, webKey);
                      } else {
                        Log.d("webKey: ", "failed to initialize");
                      }
                      // .get(0).getId().getVideoId();
                      // .getSnippet().getThumbnails().getStandard();
                      // tell the waiting object to continue
                      lock.notify();
                    }

                    // debug info to ensure our search was successful
                    if (searchResults.get(0).getId().getVideoId() != null) {
                      Log.d(
                          "newSongID: ",
                          "new song id is " + searchResults.get(0).getId().getVideoId());
                    } else {
                      Log.d("newSongID: ", "couldn't get new song id");
                    }
                  }
                };

            // creating a thread to search for the videos
            Thread threadObj = new Thread(searchTask);
            threadObj.start();

            // ensuring that we do not access the searchResults until the search has finished
            synchronized (lock) {
              try {
                // have the object wait until it is notified
                lock.wait();

                // play the first video that is returned in the searchResults
                player.loadVideo(searchResults.get(0).getId().getVideoId());
                playingVideoIndex = 0; // set our play video index to the first video
                if (searchResults != null) { // if there are results to return
                  resultTitles.clear(); // first clear the result Titles
                  // for each searchResult, set it in the result Titles
                  for (SearchResult searchResult : searchResults) {
                    resultTitles.add(searchResult.getSnippet().getTitle());
                  }
                  // create a String adapter and fill it with the searchResults
                  searchListView.setAdapter(
                      new ArrayAdapter<String>(
                          view.getContext(),
                          android.R.layout.simple_list_item_1,
                          android.R.id.text1,
                          resultTitles));
                }
              } catch (InterruptedException e) {
                e.printStackTrace();
              }
            }
          }
        });

    // if an item in the list is clicked, get it's current index in the listView, play the song
    // and set our playingVideoIndex to the correct index
    searchListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            player.loadVideo(searchResults.get(i).getId().getVideoId());
            playingVideoIndex = i;
          }
        });

    // button to return to our ClientMainActivity
    // it returns the song ID and the song title through putExtra
    returnButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            // only do something if the user actually searched for a video
            if (playingVideoIndex >= 0) {
              // get the intent that SearchActivity was started with
              Intent intent = getIntent();
              // this line and the next are ensuring that we were called by ClientMainActivity
              // by checking the contents of the intent
              // NOTE: may be removed if we don't care?
              String msg = intent.getStringExtra("song");
              if (msg.contentEquals("name")) {
                // put the song ID and song title into the intent
                intent.putExtra(
                    "Song ID", searchResults.get(playingVideoIndex).getId().getVideoId());
                intent.putExtra("Song Title", resultTitles.get(playingVideoIndex));
                intent.putExtra(
                    "Song Thumbnail",
                    searchResults
                        .get(playingVideoIndex)
                        .getSnippet()
                        .getThumbnails()
                        .getDefault()
                        .getUrl());
                // set the result to be returned, use RESULT_OK to ensure that everything went as
                // planned and return
                setResult(RESULT_OK, intent);
                finish();
              }
            } else {
              // inform user they must search for a video first
              Toast.makeText(
                      getApplicationContext(), "Search for a video first.", Toast.LENGTH_SHORT)
                  .show();
            }
          }
        });
  }