Android MediaPlayer java.io.IOException: Prepare failed.: status=0x1

后端 未结 2 905
花落未央
花落未央 2020-12-31 18:32

I am using Android\'s MediaPlayer to set up a URL stream in my application. I have tried several different posts to deal with the exit code and error: (1, -2147483648).

2条回答
  •  情话喂你
    2020-12-31 19:00

    try with this code Tested with real device Vivo V7+ Android 8.1.0

        private MediaPlayer player;
        String url = "http://199.180.75.118:80/stream";     //temp stream
        @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
        private void initializeMediaPlayer() {
            player = new MediaPlayer();
            player.setAudioAttributes( new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_MEDIA)
                    .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                    .build());
    
            try {
                //change with setDataSource(Context,Uri);
                player.setDataSource(this, Uri.parse(url));
                player.prepareAsync();
                player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    public void onPrepared(MediaPlayer mp) {
                        //mp.start();
                        player.start();
                    }
                });
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    

    Make sure u defined the permission in manifest file

    Manifest.xml

    
    
    
      //.....
      
    

    Ref :: https://developer.android.com/training/articles/security-config

    Network security configuration

    The Network Security Configuration feature lets apps customize their network security settings in a safe, declarative configuration file without modifying app code. These settings can be configured for specific domains and for a specific app. The key capabilities of this feature are as follows:

    • Custom trust anchors: Customize which Certificate Authorities (CA) are trusted for an app's secure connections. For example, trusting particular self-signed certificates or restricting the set of public CAs that the app trusts.
    • Debug-only overrides: Safely debug secure connections in an app without added risk to the installed base.
    • Cleartext traffic opt-out: Protect apps from accidental usage of cleartext traffic.
    • Certificate pinning: Restrict an app's secure connection to particular certificates.

    Add a Network Security Configuration file

    The Network Security Configuration feature uses an XML file where you specify the settings for your app. You must include an entry in the manifest of your app to point to this file. The following code excerpt from a manifest demonstrates how to create this entry:

    
    
        
            ...
        
    
    

    network_security_config.xml

    
    
        
            
                
                
            
        
    
    

提交回复
热议问题