확인이를 웹뷰하지 재생 사용하고 있습니다 코드
public class YouTube extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
public static final String API_KEY = "<---YOUR KEY--->";
public static final String VIDEO_ID = "<--VIDEO ID YOU WANT TO PLAY--->";
private static YouTubePlayer player;
TextView text;
//this is the end time in milliseconds (65th second)
public int endTime = 5600;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
text = (TextView) findViewById(R.id.text);
YouTubePlayerView youTubePlayerView = (YouTubePlayerView)findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
Toast.makeText(getApplicationContext(),
"onInitializationFailure()",
Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
MyActivity.player = player; //necessary to access inside Runnable
//start the video at 36th second
player.loadVideo(VIDEO_ID, 0);
final Handler handler = new Handler();
handler.postDelayed(() -> {
//For every 1 second, check the current time and endTime
if(MyActivity.player.getCurrentTimeMillis() <= endTime) {
text.setText("Video Playing at " + MyActivity.player.getCurrentTimeMillis());
handler.postDelayed(this, 1000);
} else {
handler.removeCallbacks(this); //no longer required
text.setText(" Reached " + endTime);
MyActivity.player.pause(); //and Pause the video
}
}, 1000);
}
}
레이아웃 XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:autoLink="web" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtubeplayerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>