因此,在我的片段中,我放入了以下代码来处理listview 的onclickitem
ls.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ChannelItem c = (ChannelItem) parent.getAdapter().getItem(position);
Intent myIntent = new Intent(getActivity().getBaseContext(), PlayerViewActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().getBaseContext().startActivity(myIntent);
}
});
我知道这不是最干净的代码,我正计划重新格式化它。但它暂时有效(在使用YoutubeBaseActivity之前,我用测试活动对它进行了测试)。只是为了澄清这段代码中没有问题,但它是为了说明我所遵循的流程。
因此,当youtube活动开始时,它会执行以下类
public class PlayerViewActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
static private final String VIDEO = "4SK0cUNMnMM";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_player);
YouTubePlayerView youTubeView = (YouTubePlayerView)
findViewById(R.id.youtube_view);
youTubeView.initialize(Api.DEV_KEY, this);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! "+error.toString(),
Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
player.loadVideo(VIDEO);
}
}
在这里找不到任何帮助
youTubeView.initialize(Api.DEV_KEY, this);
这行代码一次又一次地抛出相同的错误
Caused by: java.lang.IllegalArgumentException: callingAppVersion cannot be null or empty
at com.google.android.youtube.player.internal.ac.a(Unknown Source)
at com.google.android.youtube.player.internal.o.<init>(Unknown Source)
at com.google.android.youtube.player.internal.ad.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)
at com.google.android.youtube.player.YouTubeBaseActivity$a.a(Unknown Source)
at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
at view.PlayerViewActivity.onCreate(PlayerViewActivity.java:44)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
有人能帮我吗?
您需要将应用程序的版本代码和版本名称添加到Manifest文件中,例如:
android:versionCode="1"
android:versionName="1.0"