8
我想在您的Android應用程序中播放管視頻YouTube Api for Android異常「service_missing」
當youtube初始化像「service_missing」時,我得到了異常。
我寫下面的代碼,
package com.example.youtubedemo;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import com.google.android.youtube.player.*;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
public class MainActivity extends YouTubeBaseActivity implements OnInitializedListener{
static private final String DEVELOPER_KEY = "MY API KEY";
static private final String VIDEO = https://www.youtube.com/watch?v=d6XXgeAkBfQ&list=PLWz5rJ2EKKc9Wam5jE-9oY8l6RpeAx-XM";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
YouTubePlayerView youTubeView = (YouTubePlayerView)
findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, MainActivity.this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onInitializationFailure(Provider arg0,YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! "+error.toString(),Toast.LENGTH_LONG).show();
Toast.makeText(this, ""+YouTubeInitializationResult.SERVICE_MISSING,Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer player,
boolean arg2) {
player.loadVideo(VIDEO);
}
}
我也給互聯網用戶的權限。
我在4.2.2用google API AVD測試這段代碼。
機器人:的minSdkVersion = 「8」
機器人:targetSdkVersion = 「17」
任何一個有任何想法??
在此先感謝...
您可以使用[Genymotion](http://genymotion.com)作爲安裝了Google Play服務的模擬器,它允許您獲取Youtube應用程序。 – michaelcarrano