Jump to content

Request: Custom Radio Channel Plugin?


Recommended Posts

Posted

Many of us know about the great plugin, VirtualTV, but is there an equivalent for audio files?

I got ChatGPT to generate some code for a plugin, but I am well aware that it is probably missing a lot. But does this already exist or is someone working on it?

In the interest of transparency in case it is beneficial, here is the code ChatGPT generated:

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Logging;

public class RandomAudioChannel : ILiveTvService
{
    private readonly ILogger _logger;
    private readonly string _libraryPath;
    private readonly Random _random = new Random();

    public RandomAudioChannel(ILogger logger, string libraryPath)
    {
        _logger = logger;
        _libraryPath = libraryPath;
    }

    public Task<LiveTvServiceInfo> GetServiceInfoAsync(CancellationToken cancellationToken)
    {
        return Task.FromResult(new LiveTvServiceInfo
        {
            Name = "Random Audio Channel",
            Status = LiveTvServiceStatus.Ready
        });
    }

    public Task<ChannelInfo> GetChannelInfoAsync(string channelId, CancellationToken cancellationToken)
    {
        return Task.FromResult(new ChannelInfo
        {
            Id = channelId,
            Name = "Random Audio",
            Number = "100",
            IsTv = false
        });
    }

    public async Task<MediaSourceInfo> GetChannelStreamAsync(string channelId, CancellationToken cancellationToken)
    {
        var audioFiles = System.IO.Directory.GetFiles(_libraryPath, "*.*")
            .Where(file => new[] { ".mp3", ".wav", ".flac", ".ogg", ".m4a", ".aac", ".wma" }
            .Contains(System.IO.Path.GetExtension(file).ToLower()))
            .ToList();

        if (!audioFiles.Any())
        {
            throw new Exception("No audio files found in the specified library.");
        }

        var randomFile = audioFiles[_random.Next(audioFiles.Count)];

        _logger.Info($"Streaming file: {randomFile}");

        return new MediaSourceInfo
        {
            Path = randomFile,
            Protocol = MediaProtocol.File,
            Container = System.IO.Path.GetExtension(randomFile).TrimStart('.'),
            SupportsDirectPlay = true
        };
    }
}

public class Plugin : BasePlugin
{
    public override string Name => "Random Audio Channel";
    public override string Description => "A Live TV channel that plays random audio from a specified library.";
}

// Now it supports all common audio formats! Let me know if you'd like to refine anything else. 🚀

and here are the instructions on how to make it an actual plugin:

 

Quote

 

1. Set Up Your Environment

2. Create a Project

  • In a terminal or command prompt, run:

 

mkdir RandomAudioChannel 
cd RandomAudioChannel 
dotnet new classlib

3. Add Your Code

  • Replace the content of Class1.cs with the plugin code you already have.

4. Add Emby References

  • You’ll need the Emby server’s DLLs. Find these in your Emby installation folder. Copy them into your project (or reference their paths).

Example DLLs:

  • MediaBrowser.Controller.dll
  • MediaBrowser.Model.dll
  • MediaBrowser.Common.dll

Add references like this:

dotnet add reference path/to/MediaBrowser.Controller.dll 
dotnet add reference path/to/MediaBrowser.Model.dll 
dotnet add reference path/to/MediaBrowser.Common.dll

 

Or add them manually to your .csproj file.

5. Build the Plugin

  • Compile the project:
    dotnet build --configuration Release
  • You’ll get a .dll file in the bin/Release/netstandard2.0/ folder.

6. Deploy to Emby

  • Copy the built .dll to Emby’s plugin folder:
    /path/to/emby-server/plugins/

7. Restart Emby

  • Restart your Emby server to load the plugin.

8. Configure in Emby

  • Go to Dashboard > Plugins.
  • Configure the "Random Audio Channel" plugin — set the path to your audio library.
  • Go to Live TV — you should see your new channel!

Would you like me to help refine this setup, or add a ready-made .csproj file for you? Let me know!

 

But at this stage I am over my head! What do you guys think?

Posted

Hi, it would probably be easiest for virtual TV to add support for audio.

Posted
57 minutes ago, Luke said:

Hi, it would probably be easiest for virtual TV to add support for audio.

I will ask but it seems the guy has enough on his plate maintaining that plugin!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...