Cant get mediaplayer sound on Android 9,10 Xamarin

前端 未结 1 1595
臣服心动
臣服心动 2021-01-21 20:00

Im using this code on the android 8 and below but on Android version 9+ its not working.

MediaPlayer player3;
        player3 = new MediaPlayer();
        player         


        
相关标签:
1条回答
  • 2021-01-21 20:50

    After Android 9 (API level 28), cleartext support is disabled by default.

    Check https://koz.io/android-m-and-the-war-on-cleartext-traffic/

    Solution 1

    Create file network_security_config.xml

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <domain-config cleartextTrafficPermitted="true">
            <domain includeSubdomains="true">Your video URL(ex: 127.0.0.1)</domain>
        </domain-config>
    </network-security-config>
    

    AndroidManifest.xml -

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
        <uses-permission android:name="android.permission.INTERNET" />
        <application
            ...
            android:networkSecurityConfig="@xml/network_security_config"
            ...>
            ...
        </application>
    </manifest>
    

    Solution 2

    Android:usesCleartextTraffic Doc

    AndroidManifest.xml -

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
        <uses-permission android:name="android.permission.INTERNET" />
        <application
            ...
            android:usesCleartextTraffic="true"
            ...>
            ...
        </application>
    </manifest>
    
    0 讨论(0)
提交回复
热议问题