Hey all I am having a little bit of an issue with trying to call a fragment that has the videoview within it into my current fragment page.
When I click on the test button I set up it goes through the code without error but never shows the video fragment - I even gave it a background color of red so I could see it load into my current view.
My goal here is just to send a parameter of the video path to the video fragment videoview player and start playing it.
videoPlay.java
public class videoPlay extends Fragment { public videoPlay(){ //constructor } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout._fragvideoplay, container, false); MediaController mc= new MediaController(getActivity()); VideoView view = (VideoView)rootView.findViewById(R.id.videoView); String path = Environment.getExternalStorageDirectory().getAbsolutePath().toString() + "/sddir/Bubble Guppies.mp4"; view.setVideoURI(Uri.parse(path)); view.setMediaController(mc); view.start(); return rootView; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { } }
_fragvideoplayer.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorPrimary"> <VideoView android:id="@+id/videoView" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> </LinearLayout>
FragMovies.java:
public class FragMovies extends Fragment { public FragMovies(){ //constructor } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout._fragmovies, container, false); WebView view = (WebView) rootView.findViewById(R.id.webView); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); container.findViewById(R.id.webView).setVisibility(View.GONE); container.findViewById(R.id.pBar1).setVisibility(View.VISIBLE); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); container.findViewById(R.id.pBar1).setVisibility(View.GONE); container.findViewById(R.id.webView).setVisibility(View.VISIBLE); } }); view.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); view.getSettings().setJavaScriptEnabled(true); view.getSettings().setAllowContentAccess(true); view.getSettings().setAllowFileAccess(true); view.getSettings().setLoadsImagesAutomatically(true); view.getSettings().setAllowFileAccess(true); view.getSettings().setBuiltInZoomControls(false); view.getSettings().setDomStorageEnabled(true); view.getSettings().setAppCacheEnabled(true); view.getSettings().setDisplayZoomControls(false); view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); view.getSettings().setSupportZoom(false); view.setHorizontalScrollBarEnabled(false); view.setVerticalScrollBarEnabled(false); view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); view.loadUrl("https://www.bing.com/"); return rootView ; } }
_fragmovies.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/mainLayout"> <ProgressBar android:id="@+id/pBar1" android:layout_width="93dp" android:layout_height="match_parent" android:layout_alignParentTop="false" android:layout_centerHorizontal="true" android:layout_marginStart="950px" android:layout_marginLeft="950px" /> <WebView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/webView" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" /> </LinearLayout>
Main_activity.java:
public class MainActivity extends AppCompatActivity { TabLayout tabLayout; ViewPager viewPager; PagerAdapter pagerAdapter; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getViews(); //adapter setup pagerAdapter = new com.example.telluridetainment.PagerAdapter(getSupportFragmentManager()); //attaching fragments to adapter pagerAdapter.addFragment(new FragMovies(),"Movies"); viewPager.setOffscreenPageLimit(1); viewPager.setAdapter(pagerAdapter); tabLayout.setupWithViewPager(viewPager); //setting icons tabLayout.getTabAt(0).setIcon(R.drawable.ic_movie_white_24dp); button = (Button) findViewById(R.id.button0); button.setOnClickListener(new MyClass()); } public class MyClass implements View.OnClickListener { @Override public void onClick(View v) { videoPlay myfragment = new videoPlay(); //pass data Bundle bundle = new Bundle(); bundle.putString("KEY","DATA"); myfragment.setArguments(bundle); FragmentTransaction fragmentManager = getSupportFragmentManager().beginTransaction(); fragmentManager.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentManager.addToBackStack(null); fragmentManager.replace(R.id.viewPager, myfragment).commit(); } } private void getViews() { tabLayout = findViewById(R.id.mTabLayout); viewPager = findViewById(R.id.viewPager); } }
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="2000px" android:layout_height="1200px" tools:context=".MainActivity"> <Button android:id="@+id/button0" android:layout_width="200dp" android:layout_height="152dp" android:text="Button" android:textColor="#B71C1C" /> <android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/appbarLayout" tools:ignore="SpeakableTextPresentCheck"> </android.support.v4.view.ViewPager> </RelativeLayout>
The path to the movie is correct. And the movie is there in the "external" SD card path. Clicking around on the new fragment (videoPlay) yields no video menu (play, remind, pause...) so its not there.
Any help would be great!