Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beep sound #2

Open
Acehmshim opened this issue Jun 7, 2018 · 4 comments
Open

beep sound #2

Acehmshim opened this issue Jun 7, 2018 · 4 comments

Comments

@Acehmshim
Copy link

I am a beginner to study c #.
I want to output a beep sound.
I would like to add a beep in the source code
DisplayAlert ("Continuously Scanned Barcode", result.Text, "OK"));
using Android.Media.Tone;
I can not import.
Is there any reason not to control source code?
replay Pls

@acaliaro
Copy link
Owner

acaliaro commented Jun 7, 2018

you can't use "Android" in a XF project. You should use DependencyServices for this.

@Acehmshim
Copy link
Author

Acehmshim commented Jul 19, 2018

Dear
Windows 7, Visual Sudio 2017, and Cross Platform projectors
The ios projector has been deleted.
I refer to the Zxing related Dll using the reference later.
With the auto-generated App.xaml (App.xaml.cs) and Android projects only
I want to create a page (main) and generate a scanned page when I click the button.
After referring to Zxing related Dll
LoadApplication (new App ()); The error continues to occur, and the Dll reference is removed one by one.
ResolveLibraryProjectImports
System.IO.FileNotFoundException: Could not load assembly 'App8, Version = 0.0.0.0, Culture = neutral, PublicKeyToken ='. Perhaps it does not exist in the Mono for Android profile?
Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (AssemblyNameReference reference, ReaderParameters parameters)
.....
An error has occurred.
Is there any solution to the problem?

Is there any way to easily reference the Zxing library on Android?

@acaliaro
Copy link
Owner

I have not understand your problem. Are you using Xamarin Forms or Xamarin Android?

@Acehmshim
Copy link
Author

< MainActivity.cs >
using System;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Xamarin.Forms;
using System.Linq;

namespace App8.Droid
{
// [Activity(Label = "App8", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[Activity(Label = "App8", Icon = "@mipmap/icon", Theme = "@android:style/Theme.Material.Light", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }

}

}
< App.xaml >


<Application.Resources>

</Application.Resources>

< App.xaml.cs >
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
namespace App8
{
public partial class App : Application
{
public App ()
{
InitializeComponent();

		MainPage = new MainPage();
	}

	protected override void OnStart ()
	{
		// Handle when your app starts
	}

	protected override void OnSleep ()
	{
		// Handle when your app sleeps
	}

	protected override void OnResume ()
	{
		// Handle when your app resumes
	}
}

}
< MainPage.xaml >

<StackLayout>
    <!-- Place new controls here -->
    
    <StackLayout Margin="10,10,10,10" >
        
        <Image Source="{local:ImageResource App8.SDI_Eng_Right.png}"
               WidthRequest="100"
               HeightRequest="40"
               x:Name="imgSDI"/>
        
    </StackLayout>
	    <Label Text="QR To HMI Apps" 
            HorizontalOptions="Center"
            VerticalOptions="CenterAndExpand" 
            HorizontalTextAlignment="Center"/>
    
    <Button
            Text="SCAN"
            VerticalOptions="Center" 
            HorizontalOptions="FillAndExpand"
            BackgroundColor="LightSkyBlue"
            CornerRadius="10"
            Margin="10,10,10,10"
            Clicked="BtnSCAN_Clicked" />
    <StackLayout Orientation="Horizontal" BackgroundColor="Azure" Margin="10,10,10,10">
        <Button
            Text="HOME"
            VerticalOptions="Center" 
            HorizontalOptions="FillAndExpand"
            BackgroundColor="LightSkyBlue"
            CornerRadius="10"
            Clicked="btnHOME_Clicked" />
            
        <Button
            Text="SETTING"
            VerticalOptions="Center" 
            HorizontalOptions="FillAndExpand"
            BackgroundColor="LightSkyBlue"
            CornerRadius="15"
            Clicked="btnSETTING_Clicked" />
    </StackLayout>
    
</StackLayout>
< MainPage.xaml.cs > using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms;

using Android.Media;
using Android.OS;
using ZXing.Net.Mobile.Forms;
using Android.Content;
using Android.Content.PM;

namespace App8
{
public partial class MainPage : ContentPage
{
ZXingScannerPage scanPage;
Button buttonScanDefaultOverlay;
Button buttonScanCustomOverlay;
Button buttonScanContinuously;
Button buttonScanCustomPage;
Button buttonGenerateBarcode;

    static class Constants
    {
        public static readonly string[] EQ_INFO = { "SDI_DIV_F0001", "SDI_DIV_F0002", "SDI_DIV_F0003" };

    }


    public MainPage()
	{
		InitializeComponent();

    }

    private async void BtnSCAN_Clicked(object sender, EventArgs e)
    {
        scanPage = new ZXingScannerPage();
        scanPage.OnScanResult += (result) => {
            scanPage.IsScanning = false;

            Device.BeginInvokeOnMainThread(() => {
                Navigation.PopModalAsync();
                DisplayAlert("Default Overlay Scanned Barcode", result.Text, "OK");

                String temp = result.Text;
                CheckQR(temp);
            });
        };
        await Navigation.PushAsync(scanPage);
    }
    public void CheckQR(String readQR)
    {
        for (int i = 0; i < 2; i++)
        {
            if (Constants.EQ_INFO[i].ToString() == readQR)
            {
                TonePlayGood();
            }
            else
            {
                TonePlayError();
            }
        }
    }

    ToneGenerator tg = new ToneGenerator(Android.Media.Stream.Notification, Volume.Max);
    private MediaPlayer mediaPlayer;
    public void TonePlayGood(int ToneDuration = 200)
    {

        var v = (Vibrator)Android.App.Application.Context.GetSystemService(Android.App.Application.VibratorService);
        v.Vibrate(50);
       

        DependencyService.Get<IAudio>().PlayWavFile("1ok.wav");

        tg.StartTone(Tone.Dtmf8, 500);

    }

    public void TonePlayError(int ToneDuration = 200)
    {


        tg.StartTone(Tone.SupError, 500);

    }
    public interface IAudio
    {
        bool PlayMp3File(string fileName);
        bool PlayWavFile(string fileName);
    }
    private void btnSETTING_Clicked(object sender, EventArgs e)
    {
        Navigation.PushModalAsync(new SeconePage());
    }

    private void btnHOME_Clicked(object sender, EventArgs e)
    {

    }

    public void ExcuteHMI()
    {


    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants