VideoView的错误和错误,奇怪的行为,无法在新活动中打开VideoView

时间:2018-06-01 21:31:03

标签: javascript android-intent android-activity android-videoview

我遇到了视频观看的问题,问题是" videoescolhido.setVideoURI(videoplay);",'因为Log我可以检查是否有URI在变量(texto3)中,每次都有,但无法创建mediaPlayer,

这是我的启动码:



public class TelaHome extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {

        butvideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                launchMainActivity();
            }
        });
    }

    @Override
    public void onResume(){
        super.onResume();

        if (pacotemain != null) {
            nomedovideo = pacotemain.getString("arquivo");
            urivideo = pacotemain.getString("curPF");
            String formato = "";
            String mp4 = "mp4"; String avi = "avi"; String wmv = "wmv"; String gpp = "3gp";

            char[] lala;
            if (nomedovideo != null) {
                lala = (nomedovideo.toCharArray());
                int x = nomedovideo.length();
                for (int i = x - 3; i < x; i++) {
                    formato = (formato + lala[i]);
                }
                Log.i(TAG,"Tipo do formato=" + formato);
                if (mp4.equalsIgnoreCase(formato) || wmv.equalsIgnoreCase(formato) || avi.equalsIgnoreCase(formato) || gpp.equalsIgnoreCase(formato)){
                    textovideo.setText(nomedovideo);
                    cont++;
                    videocheck.setImageResource(R.mipmap.ic_checked);
                    simvid = true;
                }
                else{
                    textovideo.setText(nomedovideo);
                    cont=0;
                    videocheck.setImageResource(R.mipmap.ic_not_checked);
                    simvid = false;
                    Toast.makeText(TelaHome.this,
                            "Video selecionado não aceito!", Toast.LENGTH_SHORT).show();
                }
                Log.i(TAG,"Valor do cont="+ String.valueOf(cont));
            }
        }

        if (letra != null){
            legcheck.setImageResource(R.mipmap.ic_checked);
            simleg = true;
        }
        else{
            legcheck.setImageResource(R.mipmap.ic_not_checked);
            simleg = false;
        }

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                abrirplay(simvid,simleg, pacotemain, letra);
            }
        }, 1500);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (requestCode == 1) {
            if(resultCode == Activity.RESULT_OK){
                videointent = data;
                pacotemain = videointent.getExtras();
            }
        }

        if (requestCode == 7) {
            if(resultCode == Activity.RESULT_OK){
                letraintent = data;
                letra = letraintent.getExtras();
            }
        }
    }//onActivityResult


    private void launchMainActivity() {
        simvid = false;
        Intent video = new Intent(this, MainActivity.class);
        num = 1;

        Bundle bundle = new Bundle();
        bundle.putInt("numero", num);
        video.putExtras(bundle);
        startActivityForResult(video, 1);
    }


    public void clickButLeg(View view){
            tentar();
    }

    private void tentar (){
        simleg = false;
        Intent legenda = new Intent(TelaHome.this, AreaLegenda.class);
        startActivityForResult(legenda,7);

    }

    private void abrirplay(Boolean yeap, Boolean legap, final Bundle videolocal, final Bundle letra){
        if (yeap == true && legap == true){
            butstart.setVisibility(View.VISIBLE);
            butstart.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent ultima = new Intent(TelaHome.this, TelaPlay.class);
                    ultima.putExtra("video",videolocal);
                    ultima.putExtra("letra",letra);
                    startActivity(ultima);
                }
            });
        }
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        finish();
    }
}
&#13;
&#13;
&#13;

这里是视频观看的地方。

&#13;
&#13;
public class TelaPlay extends Activity {
    TextView letraatual;
    TextView letraapos;
    public VideoView videoescolhido;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tela_play);

        Intent chegou = getIntent();
        
        String texto3 = chegou.getExtras().getBundle("video").getString("curPF");

        letraatual = findViewById(R.id.letraatual);
        letraapos = findViewById(R.id.letraapos);
        videoescolhido = findViewById(R.id.videoView2);


        Log.i(TAG,texto3);

        letraapos.setText(texto3);

        try {
            // Start the MediaController
            MediaController mediaController = new MediaController(TelaPlay.this);
            mediaController.setAnchorView(videoescolhido);

            //URI para o video
            Uri videoplay = Uri.parse(texto3);
            videoescolhido.setMediaController(mediaController);
            videoescolhido.setVideoURI(videoplay);
        }

        catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        videoescolhido.requestFocus();

        videoescolhido.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                videoescolhido.start();
            }
        });
    }
}
&#13;
&#13;
&#13;

问题是当&#34; videoescolhido.setVideoURI(videoplay);&#34;,&#39;因为Log我可以检查变量(texto3)中是否有URI,并且每次都有,但无法创建mediaPlayer,

这是错误:

    06-01 18:22:00.694 21257-21257/studio.rcs.com.splayv2 D/RingtoneManager: Can't get current user. return default user
06-01 18:22:00.697 21257-21257/studio.rcs.com.splayv2 W/MediaPlayer: Couldn't open content://com.android.externalstorage.documents/document/3503-1D03%3ADCIM%2FAndy%20Mineo%20%20%20I.wmv: java.lang.SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{7afd5ff 21257:studio.rcs.com.splayv2/u0a212} (pid=21257, uid=10212) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
06-01 18:22:00.697 21257-21257/studio.rcs.com.splayv2 D/MediaPlayer: setDataSource IOException | SecurityException happend : 
                                                                     java.lang.SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{7afd5ff 21257:studio.rcs.com.splayv2/u0a212} (pid=21257, uid=10212) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
                                                                         at android.os.Parcel.readException(Parcel.java:1693)
                                                                         at android.os.Parcel.readException(Parcel.java:1646)
                                                                         at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4861)
                                                                         at android.app.ActivityThread.acquireProvider(ActivityThread.java:5958)
                                                                         at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2469)
                                                                         at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1521)
                                                                         at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1135)
                                                                         at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:988)
                                                                         at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:911)
                                                                         at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1102)
                                                                         at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1093)
                                                                         at android.widget.VideoView.openVideo(VideoView.java:356)
                                                                         at android.widget.VideoView.-wrap0(VideoView.java)
                                                                         at android.widget.VideoView$7.surfaceCreated(VideoView.java:632)
                                                                         at android.view.SurfaceView.updateWindow(SurfaceView.java:652)
                                                                         at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
                                                                         at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
                                                                         at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2492)
                                                                         at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
                                                                         at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
                                                                         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
                                                                         at android.view.Choreographer.doCallbacks(Choreographer.java:702)
                                                                         at android.view.Choreographer.doFrame(Choreographer.java:638)
                                                                         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
                                                                         at android.os.Handler.handleCallback(Handler.java:751)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:6692)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
06-01 18:22:00.703 21257-21257/studio.rcs.com.splayv2 E/MediaPlayer: Unable to create media player
06-01 18:22:00.704 21257-21257/studio.rcs.com.splayv2 W/VideoView: Unable to open content: content://com.android.externalstorage.documents/document/3503-1D03%3ADCIM%2FAndy%20Mineo%20%20%20I.wmv
                                                                   java.io.IOException: setDataSource failed.: status=0x80000000
                                                                       at android.media.MediaPlayer.nativeSetDataSource(Native Method)
                                                                       at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1173)
                                                                       at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1157)
                                                                       at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1096)
                                                                       at android.widget.VideoView.openVideo(VideoView.java:356)
                                                                       at android.widget.VideoView.-wrap0(VideoView.java)
                                                                       at android.widget.VideoView$7.surfaceCreated(VideoView.java:632)
                                                                       at android.view.SurfaceView.updateWindow(SurfaceView.java:652)
                                                                       at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:172)
                                                                       at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1013)
                                                                       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2492)
                                                                       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
                                                                       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
                                                                       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
                                                                       at android.view.Choreographer.doCallbacks(Choreographer.java:702)
                                                                       at android.view.Choreographer.doFrame(Choreographer.java:638)
                                                                       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
                                                                       at android.os.Handler.handleCallback(Handler.java:751)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6692)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
06-01 18:22:00.704 21257-21257/studio.rcs.com.splayv2 D/VideoView: Error: 1,0
06-01 18:22:00.727 21257-21257/studio.rcs.com.splayv2 D/InputTransport: Input channel constructed: fd=90

0 个答案:

没有答案