Во время проигрывания потока в момент смены трека на радио, происходит захват новых meta данных (Исполнитель и Название трека), как их вывести в Label (textbox и пр.) именно методом, а не нажимая кнопку Play.
using CSharp_Bass_Console;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Threading;
using Un4seen.Bass;
using Un4seen.Bass.AddOn.Tags;
namespace BandedSpectrumAnalyzer
{
public class BassEngine : INotifyPropertyChanged, ISpectrumPlayer
{
#region Переменные
public int Bitrate; ///Битрейт
public int freq; ///Частота дискретизации
public string Channel; ///Информация Канала
public string Artist; ///Исполнитель
public string Title; ///Трек
public string Year; ///Год выпуска трека
public string NameStation; ///Радиостанция
Dictionary<int, string> ChannelsDict = new Dictionary<int, string>()
{
{0, "Null"},
{1, "Mono"},
{2, "Stereo"}
}; ///Частота дискретизации
private static BassEngine instance; ///Singleton Instance (Чтобы класс BassEngene стал доступен в MainWindow )
public int Stream; ///Поток
private bool isPlaying; ///Проигрывается
private int maxFFT = (int)(BASSData.BASS_DATA_AVAILABLE | BASSData.BASS_DATA_FFT4096); ///Глубина анализа потока
private int sampleFrequency = 44100; ///Частота дискретизации потока
public static int volume; ///Громкость
private TAG_INFO tagInfo;
private SYNCPROC mySync, mySyncEnd;
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler<RPTagsChangedEventArgs> TagsChanged;
public event EventHandler EndStream;
public BassEngine() ///Конструктор
{
Initialize();
mySync = new SYNCPROC(MetaSync);
mySyncEnd = new SYNCPROC(SyncEnd);
}
private void MetaSync(int handle, int channel, int data, IntPtr user)
{
OnTagsChanged(handle, channel, data, user);
GetTagsFromURLStream();
}
private void SyncEnd(int handle, int channel, int data, IntPtr user)
{
OnEndStream();
GetTagsFromURLStream();
}
public TAG_INFO TagInfo { get; private set; }
public void OnTagsChanged(int handle, int channel, int data, IntPtr user)
{
EventHandler<RPTagsChangedEventArgs> handler = TagsChanged;
if (handler != null)
{
GetTagsFromURLStream();
handler(this, new RPTagsChangedEventArgs(TagInfo, handle, channel, data, user));
}
}
private void OnEndStream()
{
GetTagsFromURLStream();
EndStream?.Invoke(this, new EventArgs());
}
public static BassEngine Instance ///Singleton Instance
{
get
{
if (instance == null)
instance = new BassEngine();
return instance;
}
}
public void Play(string url, int volume)
{
if (ActiveStreamHandle != 0)
Bass.BASS_StreamFree(ActiveStreamHandle);
Stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
ActiveStreamHandle = Stream;
IsPlaying = true;
PlayCurrentStream();
Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero);
Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_META, 0, mySyncEnd, IntPtr.Zero);
GetTagsFromURLStream();
}
public void Stop()
{
if (ActiveStreamHandle != 0)
{
Bass.BASS_ChannelStop(ActiveStreamHandle);
}
IsPlaying = false;
}
void GetTagsFromURLStream()
{
TAG_INFO tagInfo = new TAG_INFO();
Bass.BASS_ChannelGetTags(Stream, BASSTag.BASS_TAG_META);
BassTags.BASS_TAG_GetFromURL(Stream, tagInfo);
TagInfo = tagInfo;
NameStation = TagInfo.album;
Artist = TagInfo.artist;
Title = TagInfo.title;
}
public static void SetVolumeToStream(int stream, int vol)
{
volume = vol;
Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, volume / 100F);
}
private void Initialize()
{
IsPlaying = false;
Window mainWindow = Application.Current.MainWindow;
WindowInteropHelper interopHelper = new WindowInteropHelper(mainWindow);
if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, interopHelper.Handle))
{
BASS_INFO info = new BASS_INFO();
Bass.BASS_GetInfo(info);
}
else
{
MessageBox.Show(mainWindow, "Bass initialization error!");
mainWindow.Close();
}
}
private void PlayCurrentStream()
{
Window mainWindow = Application.Current.MainWindow;
WindowInteropHelper interopHelper = new WindowInteropHelper(mainWindow);
// Play Stream
if (ActiveStreamHandle != 0 && Bass.BASS_ChannelPlay(ActiveStreamHandle, false))
{
BASS_CHANNELINFO info = new BASS_CHANNELINFO();
Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
sampleFrequency = info.freq;
Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, volume / 100F);
}
else
{
MessageBox.Show(mainWindow, "Что-то пошло не так");
mainWindow.Close();
}
}
private void NotifyPropertyChanged(String info)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
}
public int ActiveStreamHandle
{
get { return Stream; }
protected set
{
int oldValue = Stream;
Stream = value;
if (oldValue != Stream)
NotifyPropertyChanged("ActiveStreamHandle");
}
}
public bool IsPlaying
{
get { return isPlaying; }
protected set
{
bool oldValue = isPlaying;
isPlaying = value;
if (oldValue != isPlaying)
NotifyPropertyChanged("IsPlaying");
}
}
public int GetFFTFrequencyIndex(int frequency)
{
return Utils.FFTFrequency2Index(frequency, 4096, sampleFrequency);
}
public int GetFFTData(float[] fftDataBuffer)
{
return Bass.BASS_ChannelGetData(ActiveStreamHandle, fftDataBuffer, maxFFT);
}
}
}
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BandedSpectrumAnalyzer;
using System.Windows.Controls.Primitives;
using Just_me_default;
namespace Just_me
{
public partial class MainWindow : Window
{ private string url;
#region Dependency Properties
public static readonly DependencyProperty ScaleValueProperty = DependencyProperty.Register("ScaleValue", typeof(double), typeof(MainWindow), new UIPropertyMetadata(1.0d, new PropertyChangedCallback(OnScaleValueChanged)));
private static void OnScaleValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
MainWindow mainWindow = o as MainWindow;
if (mainWindow != null)
mainWindow.OnScaleValueChanged((double)e.OldValue, (double)e.NewValue);
}
protected virtual void OnScaleValueChanged(double oldValue, double newValue)
{
}
public double ScaleValue
{
// IMPORTANT: To maintain parity between setting a property in XAML and procedural code, do not touch the getter and setter inside this dependency property!
get
{
return (double)GetValue(ScaleValueProperty);
}
set
{
SetValue(ScaleValueProperty, value);
}
}
public string Album { get; private set; }
public string Artist { get; private set; }
#endregion
public MainWindow()
{
InitializeComponent();
BassEngine bassEngine = BassEngine.Instance;
/// UIHelper.Bind(bassEngine, "CanStop", StopButton, Button.IsEnabledProperty);
spectrumAnalyzer.RegisterSoundPlayer(bassEngine);
}
private void Hyperlink_RequestNavigate_1(object sender, RequestNavigateEventArgs e)
{
Process.Start((sender as Hyperlink).NavigateUri.ToString());
e.Handled = true;
}
private void TagINFO()
{
NameStation.Content = BassEngine.Instance.NameStation;
artist.Content = BassEngine.Instance.Artist;
title.Content = BassEngine.Instance.Title;
}
#region Button Station
private void record_chill_out(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/chil_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void megamix(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/mix_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void pirate_station(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/ps_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void pump(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/pump_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void rave_fm(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/rave_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_breaks(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/brks_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_deep(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/deep_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void radio_record(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/rr_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_techno(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/techno_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void russian_mix(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/rus_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void trance_mission(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/tm_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void wkns(object sender, RoutedEventArgs e)
{
url = "http://wknc.sma.ncsu.edu:8000/wknchq.ogg";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void vip_house(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/vip_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void yo_fm(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/yo_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_dubstep(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/dub_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_edm(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/club_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void future_house(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/fut_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void record_trap(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/trap_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void minimal_tech(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/mini_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
private void gop_fm(object sender, RoutedEventArgs e)
{
url = "http://air2.radiorecord.ru:805/gop_320";
BassEngine.Instance.Play(url, BassEngine.volume);
TagINFO();
}
#endregion
private void SliderVolume(object sender, RoutedPropertyChangedEventArgs<double> e)
{
BassEngine.SetVolumeToStream(BassEngine.Instance.ActiveStreamHandle, Convert.ToInt32(SlVolume.Value));
}
private void r(object sender, DependencyPropertyChangedEventArgs e)
{
this.NameStation.Focus();
}
}
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Одна ветка соединяется с другой (node и node_ser)Внутри них множество вложенных узлов
Делаю загрузку видео и есть необходимость обрабатывать видео на сервере, для дальнейшей публикации