user12951147
user12951147

Reputation:

cant play raw video in android studio using java

why i cant play raw video in my app? did i miss something in my code? everytime i click the name of video in my listview this error appear in my logcat 2020-11-22 12:34:40.306 8395-8426/com.ncf.fitnessandexercise E/MediaPlayerNative: error (1, -2147483648) 2020-11-22 12:34:40.325 8395-8395/com.ncf.fitnessandexercise E/MediaPlayer: Error (1,-2147483648) and

this

enter image description here

public class Zumba extends AppCompatActivity {
    VideoView videoView;
    ListView listView;
    ArrayList<String> videoList;
    ArrayAdapter<String> adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zumba);
        videoView=findViewById(R.id.videoview);
        listView=findViewById(R.id.lvideo);
        videoList= new ArrayList<>();
        videoList.add("Basic_Zumba_Steps_for_Quick_Weight_Loss_Fitness");
        videoList.add("Closer_Zumba_Live_Love_Party");
        videoList.add("Senorita_Zumba_Dance_Fitness");
        videoList.add("Short_Zumba_Dance_Workout_for_Beginners");


        adapter= new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,videoList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video));
                        break;
                    case 1:
                        videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video2));
                        break;
                    case 2:
                        videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video3));
                        break;
                    case 3:
                        videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video4));
                        break;

                    default:
                        break;
                }
                videoView.setMediaController(new MediaController(Zumba.this));
                videoView.requestFocus();
                videoView.start();
            }
        });
    }
}

this is my 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="match_parent"
    android:layout_height="match_parent"
    tools:context="com.ncf.fitnessandexercise.Zumba">

    <VideoView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/videoview"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"/>

    <ListView
        android:id="@+id/lvideo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/videoview">
    </ListView>

</RelativeLayout>

Upvotes: 3

Views: 817

Answers (3)

abdiwan
abdiwan

Reputation: 319

Please try running it on a physical device, not an emulator.

Upvotes: 0

d-feverx
d-feverx

Reputation: 1672

-2147483648 corresponds to UNKNOWN_ERROR in frameworks/native/include/utils/Errors.h

This shows that the error's source is hard to pin down as it is quite a generic return value, thrown by codec and compatibility issues as mentioned above but also thread cancellations and several other types.

you can use android exoplayer, it supports most of the video format

implementation 'com.google.android.exoplayer:exoplayer:2.X.X'

create player

SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();

Build the media item.

MediaItem mediaItem = MediaItem.fromUri(videoUri);

Set the media item to be played.

player.setMediaItem(mediaItem);

Prepare the player.

player.prepare();

Start the playback.

player.play();

github.com/google/ExoPlayer

related question on StackOverflow

Upvotes: 1

Muhammad Humza Khan
Muhammad Humza Khan

Reputation: 271

Maybe you are using non supported video format, have a look at VideoView supported formats: https://developer.android.com/guide/topics/media/media-formats

Incase if your video format is not supported, you can use ExoPlayer https://github.com/google/ExoPlayer

Upvotes: 0

Related Questions