gFinger 손끝으로 만드는 세상

 

Table Of Contens


1. How to embedded resource로 등록하기

2. nuget package 추가

3. embeded resource를 읽어서 sound 출력

4. 참조
 

 

 1. embedded resource로 등록하기

  - Sound 폴더를 프로젝트에 생성하고 mp3 파일을 등록

 - mp3 파일을 embedded resource로 등록

   솔루션 탐색기 -> 속성에서

embeded resource로 등록하기

 

embeded resource 속성

 

2.  nuget package 추가

https://github.com/adrianstevens/Xamarin-Plugins/tree/master/SimpleAudioPlayer

 

adrianstevens/Xamarin-Plugins

Cross-platform Plugins for Xamarin, Xamarin.Forms and Windows - adrianstevens/Xamarin-Plugins

github.com

 

3. embedded resource를 읽어서 sound 출력

 - sound 출력 class example

    class PlaySoundClass
    {
        ISimpleAudioPlayer soundBreath = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
        ISimpleAudioPlayer soundHold = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
        PlaySoundClass()
        {
            Stream stream;
            stream = GetDeviceInfo.GetStearmFromEmbededResource("Sound", "Breathe.mp3");
            soundBreath.Load(stream);
            stream = GetDeviceInfo.GetStearmFromEmbededResource("Sound", "HoldYourBreath.mp3");
            soundBreath.Load(stream);
        } 

        public void PlayBreahSound()
        {
            soundBreath.Play();
        }

        public void PlayHoldSound()
        {
            soundHold.Play();
        }
    }

- embedded resource read example

    public static class GetDeviceInfo
    {

        public static Stream GetStearmFromEmbededResource(string FolderName, string fileName)
        {
            TypeInfo PageInfo = typeof(GetDeviceInfo).GetTypeInfo();
            Assembly assembly = PageInfo.Assembly;

            Stream abc = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{FolderName}.{fileName}");
            return abc;
        }
     }

4. 참조

https://www.colabug.com/2017/1114/1884556/

 

Adding Sound to a Xamarin.Forms App – CoLaBug.com

Audio has many uses in mobile applications. Sounds can be essential to your app; they may notify users of important events or make your app accessible to visually-impaired users. We can also use sound to help convey moods, intentions, or feelings within ou

www.colabug.com