* activity_mythumbnail.xml
<?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="wrap_content"
android:orientation="vertical">
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true" />
</LinearLayout>
* MyThumbnail.java
public class MyThumbnail extends AppCompatActivity implements YouTubeThumbnailView.OnInitializedListener {
public static final String API_KEY = "API_KEY";
private YouTubeThumbnailLoader youTubeThumbnailLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
YouTubeThumbnailView thumbnail = findViewById(R.id.thumbnail);
thumbnail.initialize(API_KEY, this);
}
@Override
public void onInitializationFailure(YouTubeThumbnailView thumbnailView, YouTubeInitializationResult errorReason) {
}
@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView, YouTubeThumbnailLoader thumbnailLoader) {
youTubeThumbnailLoader = thumbnailLoader;
thumbnailLoader.setOnThumbnailLoadedListener(new ThumbnailListener());
youTubeThumbnailLoader.setVideo(VIDEO_ID);
}
private final class ThumbnailListener implements YouTubeThumbnailLoader.OnThumbnailLoadedListener {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView thumbnail, String videoId) {
}
@Override
public void onThumbnailError(YouTubeThumbnailView thumbnail, YouTubeThumbnailLoader.ErrorReason reason) {
}
}
}
'android' 카테고리의 다른 글
가로세로 전환시 새로고침 안되게 유지 (0) | 2020.02.21 |
---|---|
YouTube API 플레이어 (0) | 2020.02.19 |
WebView 자바스크립트 실행하기 (0) | 2020.02.17 |
WebView 사용하기 (0) | 2020.02.13 |
ExoPlayer 사용법 (0) | 2020.02.13 |