Android: Wenn Sie ein youtube-video als Vollbild ich die zurück-Taste drücken und die Aktivität fertig stellen
Ich alle gelesen habe um den Weg zu verlassen Vollbild aus einem YouTube-video, indem Sie back drücken, aber in meinem Activity
funktioniert es nicht gerne, aber ich möchte es.
Poste ich dir den code:
public class MainActivity extends YouTubeFailureRecoveryActivity {
public static String prefix = "https://gdata.youtube.com/feeds/api/playlists/";
public static String sufix = "?v=2&alt=jsonc";
private String myPlayList = "PLZGKlf2ZwY7ua0C2oeUaXQKeLKNGy3mkh";
private VideosListFragment videosFragment;
//The next video to play
private Video actualVideo;
//This is the handler that receives the response when the YouTube read
private Handler responseHandler;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videosFragment = (VideosListFragment) getFragmentManager().findFragmentById(R.id.videosListView);
getUserYouTubeFeed();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.loadVideo(actualVideo.getVideoId());
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerFragment) getFragmentManager().findFragmentById(
R.id.youtube_fragment);
}
public void getUserYouTubeFeed() {
responseHandler = new Handler() {
public void handleMessage(Message msg) {
populateListWithVideos(msg);
};
};
//We start a new AsyncTask that does its work on its own thread
//We pass in a handler that will be called when the task has finished
LoadPlayListElements bgTask = new LoadPlayListElements(responseHandler);
bgTask.execute(myPlayList);
}
/**
* This method retrieves the Library of videos from the task and passes them
* to our ListView
*
* @param msg
*/
private void populateListWithVideos(Message msg) {
Library lib = (Library) msg.getData().get(
LoadPlayListElements.LIBRARY);
VideosAdapter videos = new VideosAdapter(this, lib.getVideos());
videosFragment.setListAdapter(videos);
}
@Override
protected void onStop() {
//Make sure we null our handler when the activity has stopped
responseHandler = null;
super.onStop();
}
public void setVideo(Video _item, boolean _activate) {
actualVideo = _item;
if (_activate){
YouTubePlayerFragment fragment = (YouTubePlayerFragment) getFragmentManager()
.findFragmentById(R.id.youtube_fragment);
if (fragment != null && fragment.isInLayout()) {
fragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
}
}
}
und layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<fragment
android:id="@+id/videosListView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="?android:attr/actionBarSize"
class="com.vivoenmimundo.sc2hotsepicreplays.ui.phone.fragment.VideosListFragment" >
</fragment>
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:id="@+id/youtube_fragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_gravity="center_vertical"/>
</LinearLayout>
Irgendeine Idee? Ich habe versucht, nicht alles zu seltsam, nur copy/paste aus der YouTube-API-Beispiele.
Es sieht aus wie eine richtige Verhalten, wenn Sie die zurück-Taste drücken, wird die onStop-oder onDestory aufgerufen und die activity zerstört wird. developer.android.com/training/basics/activity-lifecycle/...
InformationsquelleAutor Nhano | 2013-03-28
Du musst angemeldet sein, um einen Kommentar abzugeben.
War es, wie gesagt, das richtige Verhalten - weil der Spieler wurde in einem fragment, das ich hatte, fangen die zurück-Taste mit:
und mein "fullScreen" boolean wie diese:
vielen Dank an alle!
setzen videoplayer-Objekts in ein Feld variable innerhalb onInitializationSuccess Methode
Das klappt nicht im fragment. Als
onBackPressed
Methode ist nicht verfügbar im fragment.InformationsquelleAutor Nhano
Schritt 1 : Folgen Sie Antwort 16 von Nhano
Schritt 2 : fügen Sie folgende Zeile in Ihre Menifest YoutubeActivity tag.
android:configChanges="orientation|screenSize"
diese Lösung funktionierte für mich..
InformationsquelleAutor Vishal2 vasundhara
Könnten Sie versuchen, zu erkennen, die zurück-Taste drücken und benutzerdefinierte definieren, was es tut.
InformationsquelleAutor Daniel Jamison