H1, ich habe meine RecyclerView Adapter mit vielen Elementen und unter ihnen, ich habe meine FrameLayout:Android - Wie stoppen und zerstören Sie alle Videos im Adapter?
<FrameLayout
android:id="@+id/video_relative_first"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/video_thumb_first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop" />
</FrameLayout>
In meinem Adapter laden i Daumen und setzen OnClickListener auf meinem FrameLayout:
if (data.getVideos().size() > 0) {
holder_all.videos_framelayout.setVisibility(View.VISIBLE);
for (int i = 0; i < 1; i++) {
final String video_id_all = getVideoId(data.getVideos().get(i));
String image_url_all = "http://img.youtube.com/vi/" + video_id_all + "/hqdefault.jpg";
Picasso.with(mContext).load(image_url_all).into(holder_all.videos_thumbs);
holder_all.videos_framelayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder_all.videos_framelayout.setId(position + 1);
VideoViewerFragment fragment = VideoViewerFragment.newInstance(video_id_all);
android.support.v4.app.FragmentManager myFragmentManager = ((AppCompatActivity) mContext).getSupportFragmentManager();
myFragmentManager.beginTransaction().replace(position + 1, fragment).commit();
}
});
}
} else {
holder_all.videos_thumbs.setImageBitmap(null);
Picasso.with(mContext).cancelRequest(holder_all.videos_thumbs);
holder_all.videos_framelayout.setVisibility(View.GONE);
}
Und ich sich einem Problem stellen. Wenn Benutzer zum Beispiel auf 2-3 Videos klicken, ist es sehr schlecht für den Speicher. Wie zerstört man alle Videos wenn man auf einen anderen klickt oder wenn man scrollt?
Auch mein Fragment:
public class VideoViewerFragment extends YouTubePlayerSupportFragment implements YouTubePlayer.OnInitializedListener {
private static final int RECOVERY_DIALOG_REQUEST = 1;
private String video_id;
public VideoViewerFragment() {}
private static final String KEY_VIDEO_ID = "KEY_VIDEO_ID";
public static VideoViewerFragment newInstance(final String videoId) {
final VideoViewerFragment youTubeFragment = new VideoViewerFragment();
final Bundle bundle = new Bundle();
bundle.putString(KEY_VIDEO_ID, videoId);
youTubeFragment.setArguments(bundle);
return youTubeFragment;
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
final Bundle arguments = getArguments();
if (bundle != null && bundle.containsKey(KEY_VIDEO_ID)) {
video_id = bundle.getString(KEY_VIDEO_ID);
} else if (arguments != null && arguments.containsKey(KEY_VIDEO_ID)) {
video_id = arguments.getString(KEY_VIDEO_ID);
}
initialize(my key, this);
}
public void setVideoId(final String videoId) {
video_id = videoId;
initialize("AIzaSyDADUNPwg8ZJ0eYVVCFWoyr07AIa4KF-XM", this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean restored) {
if (video_id != null) {
if (restored) {
youTubePlayer.play();
} else {
youTubePlayer.loadVideo(video_id);
//youTubePlayer.cueVideo(video_id);
}
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
if (youTubeInitializationResult.isUserRecoverableError()) {
youTubeInitializationResult.getErrorDialog(getActivity(), RECOVERY_DIALOG_REQUEST).show();
} else {}
}
@Override
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putString(KEY_VIDEO_ID, video_id);
}
}