daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 12-13 17:24:16.371 17097-17097/*** E/MediaPlayer: Unable to create media player
  2.    
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.     xmlns:tools="http://schemas.android.com/tools"
  6.     android:layout_width="match_parent"
  7.     android:layout_height="match_parent"
  8.     tools:context=".VideoFragment">
  9.  
  10.     <!-- TODO: Update blank fragment layout -->
  11.     <TextView
  12.         android:layout_width="match_parent"
  13.         android:layout_height="match_parent"
  14.         android:text="@string/hello_blank_fragment" />
  15.  
  16.     <VideoView
  17.         android:id="@+id/videoView"
  18.         android:layout_width="wrap_content"
  19.         android:layout_height="wrap_content"
  20.         android:layout_centerHorizontal="true"
  21.         android:layout_centerVertical="true" />
  22.  
  23. </FrameLayout>
  24.    
  25. package ***;
  26. import android.os.Bundle;
  27. import android.support.v4.app.Fragment;
  28. import android.view.LayoutInflater;
  29. import android.view.View;
  30. import android.view.ViewGroup;
  31. import android.media.MediaPlayer;
  32. import android.net.Uri;
  33. import android.support.v7.app.AppCompatActivity;
  34. import android.os.Bundle;
  35. import android.util.Log;
  36. import android.widget.MediaController;
  37. import android.widget.Toast;
  38. import android.widget.VideoView;
  39. import java.util.ArrayList;
  40. import java.util.Arrays;
  41.  
  42. /**
  43.  * A simple {@link Fragment} subclass.
  44.  */
  45. public class VideoFragment extends Fragment {
  46.  
  47.  
  48. VideoView vd;
  49.  
  50.     public VideoFragment() {
  51.         // Required empty public constructor
  52.     }
  53.  
  54.  
  55.     VideoView videoView;
  56.     ArrayList<String> arrayList = new ArrayList<>(Arrays.asList("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"));
  57.     int index = 0;
  58.  
  59.  
  60.     @Override
  61.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  62.         View v= inflater.inflate(R.layout.fragment_video, container, false);
  63.  
  64.         videoView = v.findViewById(R.id.videoView);
  65.         final MediaController mediacontroller = new MediaController(getActivity());
  66.         mediacontroller.setAnchorView(videoView);
  67.  
  68.         videoView.setMediaController(mediacontroller);
  69.         videoView.setVideoURI(Uri.parse(arrayList.get(index)));
  70.         videoView.requestFocus();
  71.  
  72.         videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
  73.             @Override
  74.             public void onPrepared(MediaPlayer mp) {
  75.                 mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
  76.                     @Override
  77.                     public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
  78.                         videoView.setMediaController(mediacontroller);
  79.                         mediacontroller.setAnchorView(videoView);
  80.  
  81.                     }
  82.                 });
  83.             }
  84.         });
  85.  
  86.         videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
  87.             @Override
  88.             public void onCompletion(MediaPlayer mp) {
  89.                 Toast.makeText(getActivity().getApplicationContext(), "Video over", Toast.LENGTH_SHORT).show();
  90.                 if (index++ == arrayList.size()) {
  91.                     index = 0;
  92.                     mp.release();
  93.                     Toast.makeText(getActivity().getApplicationContext(), "Video over", Toast.LENGTH_SHORT).show();
  94.                 } else {
  95.                     videoView.setVideoURI(Uri.parse(arrayList.get(index)));
  96.                     videoView.start();
  97.                 }
  98.  
  99.  
  100.             }
  101.         });
  102.  
  103.         videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
  104.             @Override
  105.             public boolean onError(MediaPlayer mp, int what, int extra) {
  106.                 Log.d("API123", "What " + what + " extra " + extra);
  107.                 return false;
  108.             }
  109.         });
  110.         return v;
  111.  
  112.     }
  113.  
  114. }
  115.    
  116. package ***;
  117.  
  118. import android.support.v7.app.AppCompatActivity;
  119. import android.os.Bundle;
  120. import com.stephentuso.welcome.TitlePage;
  121. import com.stephentuso.welcome.WelcomeActivity;
  122. import com.stephentuso.welcome.WelcomeConfiguration;
  123. import com.stephentuso.welcome.FragmentWelcomePage;
  124.  
  125. public class MainActivity extends WelcomeActivity  {
  126.  
  127.     @Override
  128.     protected WelcomeConfiguration configuration() {
  129.         return new WelcomeConfiguration.Builder(this)
  130.                 .defaultBackgroundColor(R.color.colorPrimary)
  131.                 .page(new FragmentWelcomePage() {
  132.                     @Override
  133.                     protected android.support.v4.app.Fragment fragment() {
  134.                         return new VideoFragment();
  135.                     }
  136.                 }.background(R.color.colorPrimary))
  137.                 .page(new TitlePage(R.drawable.lorem1, getString(R.string.label_lorem_1))
  138.                 )
  139.                 .page(new TitlePage(R.drawable.lorem2, getString(R.string.label_lorem_2))
  140.                 )
  141.                 .page(new TitlePage(R.drawable.lorem3, getString(R.string.label_lorem_3))
  142.                 )
  143.                 .swipeToDismiss(true)
  144.                 .build();
  145.     }
  146. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top