android中的Youtube API不起作用

时间:2015-04-28 03:06:05

标签: android youtube-api

我遵循了this的指示。但是不能让它发挥作用。总是得到“播放时出错”的问题。这是我的步骤:

  1. 在Google Play控制台中创建项目
  2. 为项目启用Youtube Data API
  3. 设置项目的凭据
  4. enter image description here

    1. 将从谷歌下载的示例导入Android工作室
    2. 将包名更改为com.mydomain.youtubeapidemo
    3. enter image description here

      1. 将开发者密钥更改为Google Play控制台中的密钥
      2. 但是我总是得到“播放时出错”的问题。

        顺便说一下,我使用以下命令来获取SHA1:

          

        keytool -exportcert -alias androiddebugkey -keystore   〜/ .android / debug.keystore -list -v

        可能是什么原因?谢谢你的任何建议。

        修改

        我在控制台中收到以下错误消息:

        04-27 23:25:28.132    4995-5050/? E/WVMExtractor﹕ Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
        04-27 23:25:28.961    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        04-27 23:25:28.984    4995-5058/? E/OMXNodeInstance﹕ getParameter(100663311) ERROR: 0x8000101a
        \04-27 23:25:29.046    4995-5058/? E/SoftFFmpegVideo﹕ unsupported role: video_decoder.mpeg2
        04-27 23:25:29.046    4995-5058/? E/OMXNodeInstance﹕ setParameter(16777239) ERROR: 0x80001001
        04-27 23:25:29.046    4995-5058/? E/OMXNodeInstance﹕ getParameter(100663311) ERROR: 0x8000101a
        04-27 23:25:29.046    4995-5058/? E/OMXNodeInstance﹕ getParameter(100663297) ERROR: 0x8000100e
        04-27 23:25:29.046    4995-5058/? E/OMXNodeInstance﹕ OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed
        04-27 23:25:29.161    4995-5146/? E/SoftAVC﹕ Decoder failed: -2
        04-27 23:25:29.161    4995-5060/? E/ACodec﹕ [OMX.google.h264.decoder] ERROR(0x80001001)
        04-27 23:25:29.161    4995-5060/? E/ACodec﹕ signalError(omxError 0x80001001, internalError -2147483648)
        04-27 23:25:29.162    4995-5057/? E/MediaCodec﹕ Codec reported err 0x80001001, actionCode 0, while in state 6
        04-27 23:25:29.164    4995-5056/? E/NuPlayerDecoder﹕ Failed to dequeue input buffer for OMX.google.h264.decoder (err=-38)
        04-27 23:25:29.164    4995-5049/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(0), now shutting down
        04-27 23:25:29.164    2798-2871/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:29.164    4995-5056/? E/NuPlayerDecoder﹕ failed to flush OMX.google.h264.decoder (err=-38)
        04-27 23:25:29.164    4995-5049/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(2), now shutting down
        04-27 23:25:29.164    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (1,-38)
        04-27 23:25:29.165    2798-2815/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:30.415    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        04-27 23:25:30.452    4995-5159/? E/OMXNodeInstance﹕ setParameter(1866465283) ERROR: 0x8000101a
        04-27 23:25:30.452    4995-5157/? E/OMXNodeInstance﹕ OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed
        04-27 23:25:30.452    4995-5157/? E/ACodec﹕ [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648
        
        04-27 23:25:31.983    4996-4996/? E/local_camera﹕ We have a problem with the hw connection 2 (No such file or directory)
        04-27 23:25:31.984    2798-2871/com.google.android.youtube.player E/MediaPlayer﹕ error (100, 0)
        04-27 23:25:31.984    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (100,0)
        04-27 23:25:31.987      495-554/system_process E/AudioService﹕ Media server died.
        04-27 23:25:32.068    5181-5181/? E/MonoPipe﹕ Failed to fetch local time frequency when constructing a MonoPipe (res = -32).  getNextWriteTimestamp calls will be non-functional
        04-27 23:25:32.072    5181-5181/? E/SoundTriggerHwService﹕ couldn't load sound trigger module sound_trigger.primary (No such file or directory)
        04-27 23:25:32.488      495-554/system_process E/AudioService﹕ Media server started.
        04-27 23:25:33.279    5181-5194/? E/WVMExtractor﹕ Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
        04-27 23:25:34.080    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        
        04-27 23:25:34.133    5181-5200/? E/SoftFFmpegVideo﹕ unsupported role: video_decoder.mpeg2
        04-27 23:25:34.133    5181-5200/? E/OMXNodeInstance﹕ setParameter(16777239) ERROR: 0x80001001    
        04-27 23:25:34.231    5181-5281/? E/SoftAVC﹕ Decoder failed: -2
        04-27 23:25:34.231    5181-5201/? E/ACodec﹕ [OMX.google.h264.decoder] ERROR(0x80001001)
        04-27 23:25:34.231    5181-5201/? E/ACodec﹕ signalError(omxError 0x80001001, internalError -2147483648)
        04-27 23:25:34.231    5181-5199/? E/MediaCodec﹕ Codec reported err 0x80001001, actionCode 0, while in state 6
        04-27 23:25:34.232    5181-5198/? E/NuPlayerDecoder﹕ Failed to dequeue output buffer for OMX.google.h264.decoder (err=-38)
        04-27 23:25:34.233    5181-5193/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(0), now shutting down
        04-27 23:25:34.233    5181-5198/? E/NuPlayerDecoder﹕ failed to flush OMX.google.h264.decoder (err=-38)
        04-27 23:25:34.233    2798-2814/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:34.233    5181-5193/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(2), now shutting down
        04-27 23:25:34.233    2798-2814/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:34.233    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (1,-38)
        04-27 23:25:35.513    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        04-27 23:25:35.520    5181-5292/? E/OMXNodeInstance﹕ OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed
        04-27 23:25:35.520    5181-5292/? E/ACodec﹕ [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648
        04-27 23:25:35.521    5181-5294/? E/OMXNodeInstance﹕ setParameter(1866465283) ERROR: 0x8000101a
        04-27 23:25:35.525    5181-5295/? E/SoftAVC﹕ Decoder failed: -2
        04-27 23:25:35.525    5181-5292/? E/ACodec﹕ [OMX.google.h264.decoder] ERROR(0x80001001)
        04-27 23:25:35.525    5181-5292/? E/ACodec﹕ signalError(omxError 0x80001001, internalError -2147483648)
        04-27 23:25:35.525    5181-5291/? E/MediaCodec﹕ Codec reported err 0x80001001, actionCode 0, while in state 6
        04-27 23:25:35.527    5181-5290/? E/NuPlayerDecoder﹕ Failed to dequeue input buffer for OMX.google.h264.decoder (err=-38)
        04-27 23:25:35.527    5181-5285/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(0), now shutting down
        04-27 23:25:35.527    2798-2871/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:35.528    5181-5290/? E/NuPlayerDecoder﹕ failed to flush OMX.google.h264.decoder (err=-38)
        04-27 23:25:35.528    5181-5285/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(2), now shutting down
        04-27 23:25:35.528    2798-2871/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:35.531    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (1,-38)
        04-27 23:25:36.694    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        04-27 23:25:36.709    5181-5306/? E/OMXNodeInstance﹕ setParameter(1866465283) ERROR: 0x8000101a
        04-27 23:25:36.710    5181-5307/? E/OMXNodeInstance﹕ OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed
        04-27 23:25:36.710    5181-5307/? E/ACodec﹕ [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648
        04-27 23:25:36.722    5181-5310/? E/SoftAVC﹕ Decoder failed: -2
        04-27 23:25:36.727    5181-5307/? E/ACodec﹕ [OMX.google.h264.decoder] ERROR(0x80001001)
        04-27 23:25:36.727    5181-5307/? E/ACodec﹕ signalError(omxError 0x80001001, internalError -2147483648)
        04-27 23:25:36.727    5181-5304/? E/MediaCodec﹕ Codec reported err 0x80001001, actionCode 0, while in state 6
        04-27 23:25:36.729    5181-5303/? E/NuPlayerDecoder﹕ Failed to dequeue input buffer for OMX.google.h264.decoder (err=-38)
        04-27 23:25:36.730    5181-5299/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(0), now shutting down
        04-27 23:25:36.733    2798-2871/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:36.739    5181-5303/? E/NuPlayerDecoder﹕ failed to flush OMX.google.h264.decoder (err=-38)
        04-27 23:25:36.740    5181-5299/? E/NuPlayer﹕ received error(0xffffffda) from video decoder, flushing(2), now shutting down
        04-27 23:25:36.749    2798-2859/com.google.android.youtube.player E/MediaPlayer﹕ error (1, -38)
        04-27 23:25:36.766    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (1,-38)
        04-27 23:25:38.112    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Should have subtitle controller already set
        04-27 23:25:38.125    5181-5320/? E/OMXNodeInstance﹕ OMX_GetExtensionIndex OMX.google.android.index.storeMetaDataInBuffers failed
        04-27 23:25:38.125    5181-5320/? E/ACodec﹕ [OMX.google.h264.decoder] storeMetaDataInBuffers failed w/ err -2147483648
        04-27 23:25:38.125    5181-5321/? E/OMXNodeInstance﹕ setParameter(1866465283) ERROR: 0x8000101a
        04-27 23:25:38.131    5181-5324/? A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0x60 in tid 5324 (peg.aac.decoder)
        04-27 23:25:38.238        85-85/? E/DEBUG﹕ AM write failure (32 / Broken pipe)
        04-27 23:25:38.294     495-1532/system_process E/SharedPreferencesImpl﹕ Couldn't create directory for SharedPreferences file shared_prefs/log_files.xml
        04-27 23:25:38.321    5183-5183/? E/local_camera﹕ We have a problem with the hw connection 2 (No such file or directory)
        04-27 23:25:38.321    5182-5182/? E/local_camera﹕ We have a problem with the hw connection 2 (No such file or directory)
        04-27 23:25:38.323      495-554/system_process E/AudioService﹕ Media server died.
        04-27 23:25:38.323    2798-2814/com.google.android.youtube.player E/MediaPlayer﹕ error (100, 0)
        04-27 23:25:38.323    2798-2798/com.google.android.youtube.player E/MediaPlayer﹕ Error (100,0)
        04-27 23:25:38.412    5330-5330/? E/MonoPipe﹕ Failed to fetch local time frequency when constructing a MonoPipe (res = -32).  getNextWriteTimestamp calls will be non-functional
        04-27 23:25:38.417    5330-5330/? E/SoundTriggerHwService﹕ couldn't load sound trigger module sound_trigger.primary (No such file or directory)
        04-27 23:25:38.824      495-554/system_process E/AudioService﹕ Media server started.
        

2 个答案:

答案 0 :(得分:0)

在我更改演示应用程序中的视频ID后,它可以正常工作。我不明白,如果我将视频ID从应用程序放到浏览器中,它是有效的。为什么演示应用程序中的视频无法正常工作。

答案 1 :(得分:0)

导入youtube android api演示时... 你需要在api商店添加你的api密钥。

package com.examples.youtubeapidemo;

/**
 * Static container class for holding a reference to your YouTube Developer Key.
 */
public class DeveloperKey {

  /**
   * Please replace this with a valid API key which is enabled for the
   * YouTube Data API v3 service. Go to the
   * <a href="https://console.developers.google.com/">Google Developers Console</a>
   * to register a new developer key.
   */
  public static final String DEVELOPER_KEY = "Here you need to add your youtube api key ...dllk3m6SNbpRPHZLCly6Wq1pxM";

}