开发者

Vibrate during play a ringtone in netcf C#

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.GetExecut开发者_StackOverflow社区ingAssembly().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);

    }


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);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜