Author Topic: Icecast broacasting without sound device on the VPS server  (Read 292 times)

alexeyZ

  • Posts: 18
Hi, I am developing a simple radio station using Icecast class from Bass.Net library. Locally it is working fine, but when I moved this application to the VPS I have the problem, that VPS doesn't have a soundcard. How I can run my app without a sound device to broadcast via Icecast? (I know that some 3rd party software has "Silent output" mode for this(SAM Broadcaster))

Ian @ un4seen

  • Administrator
  • Posts: 21991
You can device=0 in your BASS_Init call, for the "no sound" device. That will allow you to play files/etc without a soundcard.

alexeyZ

  • Posts: 18
I can't connect to broadcast If I set device=0 in my Bass_Init. Here my code:
Code: [Select]
        public IcecastInfo Start()
        {
            Logger.Info("IcecastService Started");

            if(!Bass.BASS_Init(/*-1*/0, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                throw new Exception("BASS_Init failed");
            }

            var song = _rotationLogicService.GetSong();

            if(song == null)
            {
                throw new Exception("Song is empty");
            }

            if (!File.Exists(song.FileName))
            {
                throw new Exception($"Song doesnt exists:{song.FileName}");
            }

            _recHandle = Bass.BASS_StreamCreateFile(song.FileName, 0, 0, BASSFlag.BASS_DEFAULT);

            _lame = new EncoderLAME(_recHandle);
            _lame.InputFile = null;
            _lame.OutputFile = null;
            _lame.LAME_Bitrate = (int)BaseEncoder.BITRATE.kbps_128;
            _lame.LAME_Mode = EncoderLAME.LAMEMode.Default;
            _lame.LAME_TargetSampleRate = (int)BaseEncoder.SAMPLERATE.Hz_44100;
            _lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;


            var serverAddress = ConfigurationManager.AppSettings["serverAddress"];
            var serverPort = ConfigurationManager.AppSettings["serverPort"];
            var serverMountPoint = ConfigurationManager.AppSettings["serverMountPoint"];

            _icecast = new ICEcast(_lame);
            _icecast.ServerAddress = serverAddress;
            _icecast.ServerPort = Convert.ToInt32(serverPort);
            _icecast.MountPoint = serverMountPoint;
            _icecast.StreamName = "Test Name";
            _icecast.StreamGenre = "Test Genre";
            _icecast.PublicFlag = true;
            _broadCast = new BroadCast(_icecast);
            _broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);

            Bass.BASS_ChannelSetAttribute(_recHandle, BASSAttribute.BASS_ATTRIB_VOL, 0f);
            _mySync = new SYNCPROC(MetaSync);
            Bass.BASS_ChannelSetSync(_recHandle, BASSSync.BASS_SYNC_END, 0, _mySync, IntPtr.Zero);

            Bass.BASS_ChannelPlay(_recHandle, false);
            _songsRepository.AddHistoryInfo(new Domain.Common.HistoryInfo
            {
                SondId = song.IdSong,
                Album = song.AlbumName,
                BandName = song.ArtistName,
                SongTitle = song.SongTitle
            });

            var songTitle = song.ArtistName + " - " + song.SongTitle;
            _icecast.UpdateTitle(songTitle, string.Empty);
           
            _broadCast.AutoConnect();

            return new IcecastInfo
            {
                Bitrate = _lame.LAME_Bitrate.ToString(),
                MountPoint = _icecast.MountPoint,
                ServerPort = _icecast.ServerPort.ToString(),
                SongTitle = songTitle,
                StationName = _icecast.StreamName
            };

        }


        private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
        {
            // Note: this method might be called from another thread (non UI thread)!
            if (_broadCast == null)
                return;
            if (_broadCast.IsConnected)
            {
                Logger.Info("BroadCast connected");
            }
            else
            {
                Logger.Info("BroadCast failed connect");
            }
        }

When I set device=-1, it is ok, I twice came into OnBroadCast_Notification method, first time _broadCast.IsConnected = false but after that I came second time with _broadCast.IsConnected = true and everything ok. If I am using device=0, I came only once with _broadCast.IsConnected = false and broadcasting didn't start

Ian @ un4seen

  • Administrator
  • Posts: 21991
Is the BASS_StreamCreateFile call successful, ie. what value does the "_recHandle" variable receive? If it's failing (returns 0), check that you're using the latest BASS.DLL version (2.4.14), as that is when support for playback on the "no sound" device was introduced. You can use BASS_GetVersion to check what version is getting loaded.

alexeyZ

  • Posts: 18
Yes it was older(33819912) version of bass.dll. Have just switched to the new version of bass.dll and set device=0 and everything works fine now, thanks a lot