I have a VideoView
that works with a lot of devices but not on others. For some time it shows my ProgressDialog
and then it fires a Popup that says Impossible to play video (translated from Italian, so it may be different but... you understand).
For example it works on Samsung Galaxy S:
But not on HTC Magic
The video I want to show is taken from a URL and it'an MP4 file.
Here's the code:
public class VideoViewActivity extends BaseActivity {
ProgressDialog progDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri videoUri = Uri.parse(getIntent().getStringExtra("url"));
setContentView(R.layout.activity_video_view);
VideoView vv = (VideoView) findViewById(R.id.videoView);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.setVideoURI(videoUri);
vv.start();
if (app.isEnglish()) {
progDialog = ProgressDialog.show(this, getResources().getString(R.string.en_wait), getResources().getString(R.string.en_load), true);
}
else {
progDialog = ProgressDialog.show(this, getResources().getString(R.string.it_wait), getResources().getString(R.string.it_load), true);
}
progDialog.setCancelable(true);
vv.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progDialog.dismiss();
}
});
}
}
That's the layout:
<RelativeLayout 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=".VideoViewActivity" >
<VideoView
android:id="@+id/videoView"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Any suggestions?
I too had the same iisue while using videoView. I managed it using device's installed media application using intent. They are doing there application for managing media, Why we want to waste our time...
PackageManager packageManager = getPackageManager();
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setDataAndType(Uri.parse(videoUrlLink),
"video/*");
List listOfSuppApps = packageManager
.queryIntentActivities(videoIntent,
PackageManager.MATCH_DEFAULT_ONLY);
if (listOfSuppApps.size() <= 0) {
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.No_supported_applications_Installed),
Toast.LENGTH_LONG).show();
} else {
Intent intnt = new Intent(Intent.ACTION_VIEW);
intnt.setDataAndType(Uri.parse(urlLink), mediaType+"/*");
context.startActivity(intnt);
}
The above is my code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.