简体   繁体   English

Android:VideoView在某些设备上不起作用

[英]Android: VideoView not working on some devices

I have a VideoView that works with a lot of devices but not on others. 我有一个VideoView ,可以在很多设备上使用,但不能在其他设备上使用。 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). 一段时间后,它会显示我的ProgressDialog ,然后触发一个弹出窗口,提示无法播放视频 (翻译自意大利语,因此可能有所不同,但是...您知道)。

For example it works on Samsung Galaxy S: 例如,它适用于三星Galaxy S:

  • Android version: 2.2.1 Android版本:2.2.1
  • Kernel version: 2.6.32.9 内核版本:2.6.32.9

But not on HTC Magic 但不是在HTC Magic上

  • Android version: 2.2 Android版本:2.2
  • Kernel version: 2.6.34.5 内核版本:2.6.34.5

The video I want to show is taken from a URL and it'an MP4 file. 我要显示的视频取自URL,它是一个MP4文件。

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. 使用videoView时我也有相同的iisue。 I managed it using device's installed media application using intent. 我使用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 以上是我的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM