gpt4 book ai didi

android - YouTube API "An error occurred while initializing the YouTube player."

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:16 25 4
gpt4 key购买 nike

我正在使用 Youtube API 在我的应用程序上使用简单的 playerView。我按照 API 的指示做了,但我不断收到“应用程序已停止”消息。我真的不知道确切的英语短语,因为我使用的是韩国电话。希望这是正确的英语短语。

我将 Youtubeandroidplayerapi.jar 放在库中并构建了路径,并在库中包含了不必要的组件。

这是 Menu.java。

package com.hobak.sci;

import com.hobak.sci.DeveloperKey;
import com.hobak.sci.R;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
import android.os.Bundle;

public class Menu extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);

YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("2LHv1FPd1Ec");
}
}

protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}

@Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub

}

}

这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFACD"
android:orientation="vertical" >


<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />



</LinearLayout>

这是我的日志

03-17 15:55:51.260: E/AndroidRuntime(5277): FATAL EXCEPTION: main
03-17 15:55:51.260: E/AndroidRuntime(5277): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hobak.sci/com.hobak.sci.Menu}: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1961)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread.access$600(ActivityThread.java:128)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1152)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.os.Looper.loop(Looper.java:137)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread.main(ActivityThread.java:4453)
03-17 15:55:51.260: E/AndroidRuntime(5277): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 15:55:51.260: E/AndroidRuntime(5277): at java.lang.reflect.Method.invoke(Method.java:511)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
03-17 15:55:51.260: E/AndroidRuntime(5277): at dalvik.system.NativeStart.main(Native Method)
03-17 15:55:51.260: E/AndroidRuntime(5277): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ContextImpl.bindService(ContextImpl.java:1164)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.google.android.youtube.player.internal.r.e(Unknown Source)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
03-17 15:55:51.260: E/AndroidRuntime(5277): at com.hobak.sci.Menu.onCreate(Menu.java:21)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.Activity.performCreate(Activity.java:4467)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-17 15:55:51.260: E/AndroidRuntime(5277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1925)
03-17 15:55:51.260: E/AndroidRuntime(5277): ... 11 more

最佳答案

我遇到了这个问题。然后我就加了

<uses-permission android:name="android.permission.INTERNET"/>进入AndroidManifest.xml<manifest>标签。之后该应用运行良好。

关于android - YouTube API "An error occurred while initializing the YouTube player.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15458351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com