Autore Topic: Errore avvio player youtube in altra activity  (Letto 560 volte)

Offline Vincenzoz

  • Utente junior
  • **
  • Post: 122
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Moto G
  • Play Store ID:
    Vincenzo Cimino
  • Sistema operativo:
    Windows 7
Errore avvio player youtube in altra activity
« il: 18 Novembre 2013, 18:58:53 CET »
0
Salve di recente ho provato ad implementare il player ufficiale di youtube alla seguene maniera.

File xml:

Codice (XML): [Seleziona]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_gravity="center"
   android:gravity="center_horizontal"
   android:orientation="vertical" >

    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_margin="12dip"
       android:text="Hello YouTube API" />

    <com.google.android.youtube.player.YouTubePlayerView
       android:id="@+id/youtube_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_margin="12dip"
       android:layout_weight="1" />

</LinearLayout>

File java:

Codice (Java): [Seleziona]
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.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;

import android.os.Bundle;

public class z extends YouTubeBaseActivity implements OnInitializedListener {

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

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

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

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

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

}

E funzionava alla perfezione, ma il problema è che dopo l'ho implementato in un applicazione dove questa activity viene aperta al click su un elemento di una listview e da i seguenti errori nei log, facendo crashare l'app:

11-18 19:48:30.703: E/AndroidRuntime(32057): FATAL EXCEPTION: main
11-18 19:48:30.703: E/AndroidRuntime(32057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wtt/com.example.wtt.z}: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.os.Looper.loop(Looper.java:130)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread.main(ActivityThread.java:3687)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at java.lang.reflect.Method.invokeNative(Native Method)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at java.lang.reflect.Method.invoke(Method.java:507)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at dalvik.system.NativeStart.main(Native Method)
11-18 19:48:30.703: E/AndroidRuntime(32057): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.youtube.api.service.START }
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ContextImpl.bindService(ContextImpl.java:889)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.google.android.youtube.player.internal.r.e(Unknown Source)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at com.example.wtt.z.onCreate(z.java:21)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-18 19:48:30.703: E/AndroidRuntime(32057):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
11-18 19:48:30.703: E/AndroidRuntime(32057):    ... 11 more


Ma non riesco a capire, perché ?  :-o Grazie mille in anticipo !

Post unito: 18 Novembre 2013, 20:05:55 CET
Ho risolto avevo dimenticato di aggiungere nel manifest:

Codice (XML): [Seleziona]
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
« Ultima modifica: 18 Novembre 2013, 20:05:55 CET da Vincenzoz, Reason: Merged DoublePost »
Vincenzo Cimino @ Google Play Store