Online video does not play

I follow the tutorial on playing video in Android, the tutorial is here

But when I run the application on the emulator, it gives me the following error

MediaPlayer Error (1, -2147483648)

Please, help

Here is the code of my application

Java

package com.example.videoplayer; import android.media.MediaPlayer; import android.media.MediaPlayer.OnErrorListener; import android.media.MediaPlayer.OnPreparedListener; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.graphics.PixelFormat; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.MediaController; import android.widget.ProgressBar; import android.widget.Toast; import android.widget.VideoView; public class MainActivity extends Activity { public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"; private VideoView videoView = null; private ProgressBar prog = null; private Context ctx = null; private MediaController mediaController = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.activity_main); ctx = this; prog = (ProgressBar) findViewById(R.id.prog); videoView = (VideoView) findViewById(R.id.video); Uri video = Uri.parse(url); mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController); videoView.setVideoURI(video); videoView.setOnErrorListener(new OnErrorListener(){ @Override public boolean onError(MediaPlayer mp, int what, int extra) { // TODO Auto-generated method stub Toast.makeText(ctx, "Error occured", 500).show(); return false; } }); videoView.setOnPreparedListener(new OnPreparedListener(){ @Override public void onPrepared(MediaPlayer arg0) { // TODO Auto-generated method stub prog.setVisibility(View.GONE); videoView.start(); } }); } @Override protected void onDestroy(){ try{ videoView.stopPlayback(); } catch(Exception e) { Log.d("MideoPlayer", "Error OnDestroy"); } super.onDestroy(); } } 

XML

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <VideoView android:id="@+id/video" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center"/> <ProgressBar android:id="@+id/prog" android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center"/> </FrameLayout> </LinearLayout> 

and manifest

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.videoplayer" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.videoplayer.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 
+4
source share
1 answer

Adding this as an answer here to help others with this problem - I saw that this error occurs mainly only on emulators and seems to work well on the device. There may be a problem with the emulator setting, and I will update this topic if I find any official posts. I only saw this on the device, if I try to play an unsupported format like wmv. If anyone has links to this problem on the emulator, please add

+1
source

Source: https://habr.com/ru/post/1492497/


All Articles