Jump to content
php.lv forumi

Csharp problema


Recommended Posts

Sveiki visiem,esu sacis darboties ar c#.

Un nekadi nevaru saprast kas man te pa vainu:
 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;

namespace radio
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            new WindowsMediaPlayer() { URL = "http://www.radioskonto.lv/online_radio/stereo.m3u" }.controls.play();

        }

        private void Button2_Click(object sender, EventArgs e)
        {
           
        }
    }
}

Problema tada ka ir ideja lai kad uzspiezot uz pogas skan radio,un uzspiezot atpakal apstajas(Uz tas pasas pogas) un tada gara ar visam stacijam,izrakaju googli neko neatradu.

Paldies,ceru uz kadu atbildi :)

Link to comment
Share on other sites

Tev objekts WindowsMediaPlayer jāsaglabā privātajā mainīgajā. Tad, spiežot play, paskaties, kāds ir stāvoklis - vai tobrīd spēlē un un kādu staciju spēlē. Ja spēlē izvēlēto, tad izslēdz, pretējā gadījumā uzliek pareizo URLi un palaiž play().

Link to comment
Share on other sites

Nu, apmēram šādi man strādā. Pāris sekundes gan jāpagaida, līdz sāk spēlēt.

using System;
using System.Collections.Generic;
using System.Windows;
using WMPLib;

namespace Radio
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private WindowsMediaPlayer _player;
        private Dictionary<int, string> _urls = new Dictionary<int, string> {
            { 1, "http://www.radioskonto.lv/online_radio/stereo.m3u" },
            { 2, "http://live.pieci.lv/live19-hq.mp3" },
        };
        private int _active = -1;

        public MainWindow()
        {
            InitializeComponent();
            _player = new WindowsMediaPlayer();
        }

        private void Play(int station)
        {
            if (_active == station)
            {
                _player.controls.stop();
                _active = -1;
                return;
            }

            _player.URL = _urls[station];
            _player.controls.play();
            _active = station;
        }

        private void Btn1_Click(object sender, RoutedEventArgs e)
        {
            Play(1);
        }

        private void Btn2_Click(object sender, RoutedEventArgs e)
        {
            Play(2);
        }
    }
}

 

Link to comment
Share on other sites

Paldies e-remit,problema atrisinata :)

 

Janu kadam noder,te bus ar visu source -->

T a izskatas,vnk ,lai nav katru reizi browseris javer vala tad vismaz man noder si neliela programma :)

 

https://failiem.lv/u/xn2v4wqv

 

https://prnt.sc/ol2dl7

 

Edited by emilsD
Link to comment
Share on other sites

2 hours ago, jurgenzz said:

Sarežģīti būs to darot pirmās 5-7x :)

Pēc tam kļūs vieglāk, bet atmetot uzreiz ar roku un sakot, ka "tas viss ir sarežģīti", vieglāk nepaliks nevienā no reizēm :)

Piekritu,mekleju tagad risinajumu :)

+ bezmaksas  nemaz nevar atrast es domaju api.

 

Nesaprotu kas pa problemu,nesanak aizsutit errors failure to send mail. hmmm

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace smssutit
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            MailMessage message = new MailMessage();
            message.To.Add("37122222222@txt.att.net");//te jabut kautkam citam
            message.From = new MailAddress("kautkas@gmail.com", "App");
            message.Body = "Sveiki";
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.EnableSsl = true;
            smtp.Port = 465;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential("kautkas@gmail.com", "tava parole");

            try
            {
                smtp.Send(message);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

 

Edited by emilsD
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...