Android MediaPlayer won't play music on API 26+

后端 未结 3 1672
死守一世寂寞
死守一世寂寞 2021-01-12 09:37

I have an app that streams music for the user, this code works fine ok on devices running Android up to API 25, when i test in a device running API 26 or greater the Music w

3条回答
  •  迷失自我
    2021-01-12 10:11

    You need to define a res/xml/network_security_config.xml and permit HTTP for that host:

    
    
        
            server.com
        
    
    

    That network_security_config.xml also needs to be referenced in the Manifest.xml:

    
    
        
                ...
        
    
    

    The SDK documentation explains it all in detail - and this applies to all network traffic an app creates.

    Instead of lowering the security standards, upgrading the connection to HTTPS should be preferred.


    And concerning that one deprecated method .setAudioStreamType(), use .setAudioAttributes() instead - as your code already does. It does not seem to be the "main problem" here; verified that.

提交回复
热议问题