3
我在我的應用程序中使用Youtube Player API來播放YouTube視頻。我想從36秒開始播放視頻,並希望在65秒內結束這段視頻。如何在youtube Android播放器中爲YouTube視頻提供開始和結束參數?
例如:https://www.youtube.com/v/BmOpD46eZoA?start=36&end=65
我使用youtubeAndroidPlayer API。我沒有找到Youtubeplayer設置開始和結束值的任何方法。任何人都可以建議如何設置參數。
而且我也希望使用youtube api中的「controls」字段來隱藏控件,但是我沒有找到任何方法來隱藏它。
我的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: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>
我的活動:
public class MainActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener{
public static final String API_KEY = "AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA";
public static final String VIDEO_ID = "xyoajjlPt_o";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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) {
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
非常感謝您的回答,我如何隱藏/顯示控件。 – user1891910
@ user1891910您可以將播放器樣式設置爲「無色」。爲此,請使用:'MyActivity.player.setPlayerStyle(YouTubePlayer.PlayerStyle.CHROMELESS);'並將其放入'else'部分。通讀文檔,你會很容易地得到你的答案 - https://developers.google.com/youtube/android/player/ – JoelFernandes
嗨,我也使用這個Youtube api對於加載視頻,但這個api不起作用,最新版本4.0以上當我嘗試加載視頻它顯示intializer錯誤可以請你建議我笏我可以做什麼? - JoelFernandes – ishu