Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 12-13 17:24:16.371 17097-17097/*** E/MediaPlayer: Unable to create media player
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".VideoFragment">
- <!-- TODO: Update blank fragment layout -->
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:text="@string/hello_blank_fragment" />
- <VideoView
- android:id="@+id/videoView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true" />
- </FrameLayout>
- package ***;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.media.MediaPlayer;
- import android.net.Uri;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.widget.MediaController;
- import android.widget.Toast;
- import android.widget.VideoView;
- import java.util.ArrayList;
- import java.util.Arrays;
- /**
- * A simple {@link Fragment} subclass.
- */
- public class VideoFragment extends Fragment {
- VideoView vd;
- public VideoFragment() {
- // Required empty public constructor
- }
- VideoView videoView;
- 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"));
- int index = 0;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View v= inflater.inflate(R.layout.fragment_video, container, false);
- videoView = v.findViewById(R.id.videoView);
- final MediaController mediacontroller = new MediaController(getActivity());
- mediacontroller.setAnchorView(videoView);
- videoView.setMediaController(mediacontroller);
- videoView.setVideoURI(Uri.parse(arrayList.get(index)));
- videoView.requestFocus();
- videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
- @Override
- public void onPrepared(MediaPlayer mp) {
- mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
- @Override
- public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
- videoView.setMediaController(mediacontroller);
- mediacontroller.setAnchorView(videoView);
- }
- });
- }
- });
- videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer mp) {
- Toast.makeText(getActivity().getApplicationContext(), "Video over", Toast.LENGTH_SHORT).show();
- if (index++ == arrayList.size()) {
- index = 0;
- mp.release();
- Toast.makeText(getActivity().getApplicationContext(), "Video over", Toast.LENGTH_SHORT).show();
- } else {
- videoView.setVideoURI(Uri.parse(arrayList.get(index)));
- videoView.start();
- }
- }
- });
- videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- public boolean onError(MediaPlayer mp, int what, int extra) {
- Log.d("API123", "What " + what + " extra " + extra);
- return false;
- }
- });
- return v;
- }
- }
- package ***;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import com.stephentuso.welcome.TitlePage;
- import com.stephentuso.welcome.WelcomeActivity;
- import com.stephentuso.welcome.WelcomeConfiguration;
- import com.stephentuso.welcome.FragmentWelcomePage;
- public class MainActivity extends WelcomeActivity {
- @Override
- protected WelcomeConfiguration configuration() {
- return new WelcomeConfiguration.Builder(this)
- .defaultBackgroundColor(R.color.colorPrimary)
- .page(new FragmentWelcomePage() {
- @Override
- protected android.support.v4.app.Fragment fragment() {
- return new VideoFragment();
- }
- }.background(R.color.colorPrimary))
- .page(new TitlePage(R.drawable.lorem1, getString(R.string.label_lorem_1))
- )
- .page(new TitlePage(R.drawable.lorem2, getString(R.string.label_lorem_2))
- )
- .page(new TitlePage(R.drawable.lorem3, getString(R.string.label_lorem_3))
- )
- .swipeToDismiss(true)
- .build();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement