我在YouTubePlayerSupportFragment
中挣扎了3天,试图让它在swipe片段中运行。现在显示这个错误,我尝试了其他方法,得到NullPointerException
。是否有可能将YouTubePlayerSupportFragment
放入swipe片段中?
java.lang.UnsupportedOperationException:在com.google.android.youtube.player.youtubePlayerView.a(未知来源)在com.google.android.youtube.player.youtubePlayerView.addView(未知来源)在android.support.v4.app.fragmentManagerImpl.moveTostate(fragmentManager.java:1083)在android.support.v4.app.fragmentManagerImpl.moveTostate(在Android.support.v4.app.fragmentManagerImpl.executePendingActions(fragmentManager.java:1617)在Android.support.v4.app.fragmentStatePagerAdapter.FinishUpdate(fragmentStatePagerAdapter.java:570)在Android.support.v4.view.viewPager.populate(ViewPager.java:164)在Android.support.v4.viewPager.java:1177)在roid.view.view.measure(view.java)在Android.view.viewgroup.measureChildWith Margins(viewgroup.java)在Android.widget.linearlayout.measureChildbeRelayout(linearlayout.java)在Android.widget.linearlayout.measureVertical(linearlayout.java)在Android.widget.linearlayout.java在Android.widget.linearlayout.onMeasure(linearlayout.java)layout.java:668)在Android.support.design.widget.coordinatorlayout.onMeasure(coordinatorlayout.java:735)在Android.support.v4.widget.drawerlayout.measure(view.java)在Android.support.v4.widget.drawerlayout.onMeasure(drawerlayout.java:1075)在Android.view.view.view.java)在Android.view.view.view.view.javaout.java:135)在Android.view.view.measure(view.java)在Android.view.viewgroup.measureChildWith Margins(viewgroup.java)在Android.widget.linearlayout.measureChildbeRelayout(linearlayout.java)在Android.widget.linearlayout.java在Android.widget.linearlayout.measureChildbeRelayout(linearlayout.java)在在Android.view.viewgroup.measureChildWithMargins(viewgroup.java)在Android.widget.linearlayout.measureChildbeforelayout(linearlayout.java)在Android.widget.linearlayout.measureVertical(linearlayout.java)在Android.widget.linearlayout.onMeasure(linearlayout.java)在Android.widget.linearlayout.onMeasure(ecorview.onMeasure(phoneWindow.java)在Android.view.view.view.java在Android.view.viewrootimpl.performMeasure(viewrootimpl.java)在Android.view.viewrootimpl.measury层次结构(viewrootimpl.java)在Android.view.viewrootimpl.measury层次结构(viewrootimpl.java)在Android.view.viewrootimpl.performTraversals(viewrootimpl.java在docallbacks(choreographer.java)在Android.view.choreographer.doFrame(choreographer.java)在Android.view.choreographer$FrameDisplayEventReceiver.run(choreographer.java)在Android.os.handler.handleCallback(handler.java)在Android.os.handler.dispatchMessage(handler.java)在Android.app.activityThread.java在Android.app.activityThread.main(
MainActivity.java:
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@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 boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
pageradapter.java:
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
TabFragment1 tab1 = new TabFragment1();
return tab1;
case 1:
TabFragment2 tab2 = new TabFragment2();
return tab2;
case 2:
TabFragment3 tab3 = new TabFragment3();
return tab3;
default:
return null;
}
}
@Override
public int getCount() {
return mNumOfTabs;
}
}
tabfragment1.java:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
public class TabFragment1 extends Fragment {
private String currentVideoID = "nCgQDjiotG0";
public static final String API_KEY = "XXX";
private YouTubePlayer YPlayer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.tab_fragment_1, container, false);
YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.youTubePlayer, youTubePlayerFragment).commit();
youTubePlayerFragment.initialize(API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider arg0, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
YPlayer = youTubePlayer;
YPlayer.setFullscreen(true);
YPlayer.loadVideo("2zNSgSzhBfM");
YPlayer.play();
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider arg0, YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
});
return rootView;
}
tab_fragment_1.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youTubePlayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
先代替
<fragment
android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
android:id="@+id/youTubePlayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
使用FrameLayout
<FrameLayout
android:id="@+id/frame_fragment"
android:layout_width="match_parent"
android:layout_height="200dp"></FrameLayout>
然后在初始化后使用
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_fragment, youTubePlayerFragment);
transaction.commit();
播放器的设置与选择,将控制用户前台播放效果,用户可以添加多款播放器,实现同一帐号下的视频调用不同样式的播放器。 3.1添加新播放器 进入播放器页面,点击添加播放器按钮,在弹出的添加播放器页面中填写播放器相关信息,保存即可。 添加播放器页面: 播放器相关信息说明: · 播放器名称:最大字数限制10个字符(中英文均是10个字符),但不可以重复; · 播放器类型:播放器分为基础类和展示类。 基础类是常规
嗨,我有几个视频不能在Android(直接在Chrome上)和iOS(直接在Safari上)上播放,但可以在Windows、Mac和Linux上任何浏览器上播放。 下面是输出 下面是另一段在Android和Chrome上播放的视频的ffprobe输出: 两者都是.mp4格式,并使用编解码器。就我所见,我注意到编解码器配置文件与和与以及元数据部分的差异。 我尝试用ffmpeg重新编码第一个视频,但没
我已经创建了一个视频从图像使用ffmpeg和H264编解码器在C。我可以运行视频使用第三方播放器(V播放器)在android设备上。但是本机播放器不播放视频。它说该文件不是Divx文件。下面是我用来从图像创建视频的代码: 上述代码产生了一个视频,可以使用第三方播放器如VLC运行。我只想知道我错过了什么让视频在android上播放,我如何才能删除“不是一个divx文件”错误。
尝试过添加loop: true、 监听视频播放结束后重新播放等方式都是h5正常,app会一直转圈
我的XML代码: 片断中的代码 java.lang.NullPointerException:试图对com.google.Android.YouTube.Player.YouTubePlayerSupportFragment.OnStart(未知源)上的空对象引用调用虚拟方法“void com.google.Android.YouTube.Player.YouTubePlayerView.a()”
我在Box2d上遇到了问题,因为我是Box2d新手,所以无法处理我的播放器的移动。当用户在我的游戏中触摸左右按钮时,我想将我的玩家左右移动。在我的游戏中,玩家已经通过了y轴。我想在控制播放器的同时看到很酷的平滑动画。我就是不能把我的球员移到左边我怎么能做到?提前谢谢 //编辑 我创建了一个测试夹具,我可以移动夹具,但不能移动我的球员。如何将我的玩家精灵连接到身体上?我必须找到控制身体的正确方法。一