YouTube API 플레이어

android 2020. 2. 19. 15:31

* lib 폴더에 라이브러리 추가

YouTubeAndroidPlayerApi-1.2.2.zip
0.63MB

* activity_myplayer.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="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.youtube.player.YouTubePlayerView
            android:id="@+id/youTubePlayerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
	
    </LinearLayout>

</LinearLayout>

* MyPlayerActivity.java

public class MyPlayerActivity extends YouTubeBaseActivity {

    public static final String API_KEY = "API_KEY";

    YouTubePlayerView youTubePlayerView;
    YouTubePlayer.OnInitializedListener listener;

    public PlayerActivity() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_player);

        Intent intent = getIntent();
        final ArrayList<String> idList = (ArrayList<String>) intent.getSerializableExtra("idList");

        youTubePlayerView = findViewById(R.id.youTubePlayerView);
        listener = new YouTubePlayer.OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean b) {
                youTubePlayer.loadVideo(VIDEO_ID);
            }

            @Override
            public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

            }
        };

        youTubePlayerView.initialize(API_KEY, listener);
    }

}

'android' 카테고리의 다른 글

Geocoder 주소 > 위도, 경도 변환  (0) 2020.03.02
가로세로 전환시 새로고침 안되게 유지  (0) 2020.02.21
YouTube 썸네일(Thumbnail)  (0) 2020.02.19
WebView 자바스크립트 실행하기  (0) 2020.02.17
WebView 사용하기  (0) 2020.02.13
블로그 이미지

디츠

“말은 쉽지, 코드를 보여줘.” “Talk is cheap. Show me the code.” – 리누스 토르발스(Linus Torvalds)

,