在 netcf C# 中播放铃声时振动

发布于 2024-10-04 23:09:06 字数 2211 浏览 4 评论 0原文

我需要在播放铃声时振动手机。

这是我的代码:

   public static bool PlaySound(string soundName)
    {
        try
        {
            WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
            string MediaFile = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + soundName;
            player.URL = MediaFile;
            WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();

            player.settings.volume = 100;
            player.controls.play();
            SetVibrate(true);
            System.Threading.Thread.Sleep((int)wmp.newMedia(MediaFile).duration*1000 + 100);
            SetVibrate(false);
            return true;
        }
        catch
        {
            return false;
        }
    }

我的问题是手机首先振动,然后播放声音..不可能在声音持续时间内振动?

谢谢。

@x86shadow:我尝试使用线程但不起作用:(

   public static bool PlaySound(string soundName)
    {
        try
        {
            // 29/11/2010 Luca - Aggiungo vibrazione durante il suono del messaggio.
            WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();

            string MediaFile = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + soundName;
            player.URL = MediaFile;
            WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();

            player.settings.volume = 100;
            RingDuration = (int) wmp.newMedia(MediaFile).duration*1000 + 100;

            VibrateWhilePlayingThread = new Thread(VibrateWhilePlaying);


            VibrateWhilePlayingThread.Start();

            player.controls.play();

            VibrateWhilePlayingThread.Join();

            return true;
        }
        catch
        {
            return false;
        }
    }

    private static int RingDuration;

    public static Thread VibrateWhilePlayingThread;

    public static void VibrateWhilePlaying()
    {
        SetVibrate(true);
        System.Threading.Thread.Sleep(RingDuration);
        SetVibrate(false);

    }

i need to vibrate the phone while playing a ringtone.

This is my code:

   public static bool PlaySound(string soundName)
    {
        try
        {
            WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
            string MediaFile = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + soundName;
            player.URL = MediaFile;
            WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();

            player.settings.volume = 100;
            player.controls.play();
            SetVibrate(true);
            System.Threading.Thread.Sleep((int)wmp.newMedia(MediaFile).duration*1000 + 100);
            SetVibrate(false);
            return true;
        }
        catch
        {
            return false;
        }
    }

My problem is that the phone FIRST vibrate, then Play sound.. is not possibile to vibrate for the duration of the sound?

thanks.

@x86shadow: I tried with thread but not working :(

   public static bool PlaySound(string soundName)
    {
        try
        {
            // 29/11/2010 Luca - Aggiungo vibrazione durante il suono del messaggio.
            WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();

            string MediaFile = Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(0, Assembly.GetExecutingAssembly().GetName().CodeBase.LastIndexOf("\\")) + "\\Resources\\" + soundName;
            player.URL = MediaFile;
            WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();

            player.settings.volume = 100;
            RingDuration = (int) wmp.newMedia(MediaFile).duration*1000 + 100;

            VibrateWhilePlayingThread = new Thread(VibrateWhilePlaying);


            VibrateWhilePlayingThread.Start();

            player.controls.play();

            VibrateWhilePlayingThread.Join();

            return true;
        }
        catch
        {
            return false;
        }
    }

    private static int RingDuration;

    public static Thread VibrateWhilePlayingThread;

    public static void VibrateWhilePlaying()
    {
        SetVibrate(true);
        System.Threading.Thread.Sleep(RingDuration);
        SetVibrate(false);

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-11 23:09:07

添加事件处理程序:

Player.PlayStateChanged += new AxWMPLib._WMPOCXEvents_PlayChangeEventHandler(player_PlayStateChange);

尝试创建一个事件:

    private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if (Player.playState == WMPLib.WMPPlayState.wmppsPlaying)
        {
            SetVibrate(true);
        }
        else
        {
            SetVibrate(false);
        }
    }

Adding an EventHandler:

Player.PlayStateChanged += new AxWMPLib._WMPOCXEvents_PlayChangeEventHandler(player_PlayStateChange);

Try to create an Event:

    private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if (Player.playState == WMPLib.WMPPlayState.wmppsPlaying)
        {
            SetVibrate(true);
        }
        else
        {
            SetVibrate(false);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文