1

1.在MainActivity上初始化CrossMediaManager

protected override void OnCreate(Bundle savedInstanceState)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    base.OnCreate(savedInstanceState);

    Xamarin.Essentials.Platform.Init(this, savedInstanceState);
    global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

    CrossMediaManager.Current.Init(this);

    LoadApplication(new App());
 }

2. 点击按钮执行播放功能

var mediaItem = await CrossMediaManager.Current.Play("http://tasfiaradio.servemp3.com:8000/tasfia1");

IMediaItem mediaFile = await CrossMediaManager.Current.Extractor.CreateMediaItem("http://tasfiaradio.servemp3.com:8000/tasfia1"); 
var mediaItem = await CrossMediaManager.Current.Play(mediaFile);

预期行为

听到声音

配置

Plugin.MediaManager:0.9.7 Xamarin.Forms:4.5.0.495

4

1 回答 1

0

默认情况下,Android 只允许 https 流量,将android:usesCleartextTraffic="true"添加到对我有用的应用程序标签。下面是 AndroidManifest 配置文件内容。

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" package="com.testcrossmediaplayer" 
      android:installLocation="auto" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" />
<application android:label="Test Cross Media Player" android:usesCleartextTraffic="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

于 2020-06-05T19:21:22.857 回答