在媒体播放器中使用来自 android 项目的文件 [英] Using file from android project in media Player
本文介绍了在媒体播放器中使用来自 android 项目的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
enter image description here i have a mobile application that is dedicated to playing articles using MediaPlayer
. I am trying to set the pause between individual sentences however i keep getting null reference
at the pausesPlayer
so accesing the mp3 files in my droid project from shared project
must be wrong. Please do you have any experience with how to acess the file in droid without Main Activity
MediaPlayer.Create(MainActivity.Instance, Resource.Raw.silent_1);
public static void SetPauseBetweenSentences(int timeout)
{
lock (syncRoot)
{
pausesPlayer = new MediaPlayer();
if (timeout != 0)
{
switch (timeout)
{
case 1:
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("AT.Droid/Resources/raw/silent_1"));
break;
case 2:
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("AT.Droid/Resources/raw/silent_2"));
break;
case 3:
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("AT.Droid/Resources/raw/silent_3"));
break;
case 4:
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("AT.Droid/Resources/raw/silent_4"));
break;
case 5:
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("AT.Droid/Resources/raw/silent_5"));
break;
}
pausesPlayer.Start();
}
}
}
I have tried
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("android.resource://AT.Droid/Resources/raw/silent_1"));
and
pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Android.Net.Uri.Parse("android.resource://AT/Resources/raw/silent_1"));
解决方案
From the document, you can use:
Convenience method to create a MediaPlayer for a given resource id.
public static Android.Media.MediaPlayer Create (Android.Content.Context context, int resid);
And in your case, it is:
MediaPlayer player = MediaPlayer.Create(this, Resource.Raw.silent_1);
For more solutions, you can have a look at this thread.
Update:
这篇关于在媒体播放器中使用来自 android 项目的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文