Mp3Player updated for BlogEngine 1.3

There is a new version of Mp3 flash audio player extension for BlogEngine 1.3 available for download. Please note that it will not work with BE 1.2 because it uses Extension Manager. The new in this version is an admin page that will let you to change how player looks. You’ll be able to change colors and sizes through the settings interface. I did this as an exercise to show how you can use your own admin page AND still take advantage of some of the Extension Manager features. You can refer to the source code for details, but here is a brief overview steps that you can follow. First, Extension Manager need to know that you want to use custom admin page for your extension, and this is done by using SetAdminPage method:

public mp3player()
{
    // subscribe for post serving event
    Post.Serving += new EventHandler<ServingEventArgs>(Post_Serving);
    // set page that Extension Manager will use  
    // instead of default settings page
    ExtensionManager.SetAdminPage("mp3player", "~/audio/Admin.aspx");
    // set default setting values
    SetDefaultSettings();
}

Then you set default settings. These settings will be serialized to XML first time Extension Manager will see your extension on application start for future use.

protected void SetDefaultSettings()
{
    ExtensionSettings settings = new ExtensionSettings(_ext);
    settings.AddParameter(_width);
    settings.AddParameter(_height);
    settings.AddParameter(_bgColor);
    //more...
    settings.AddValue(_width, "290");
    settings.AddValue(_height, "24");
    settings.AddValue(_bgColor, "ffffff");
    //more...   
    settings.IsScalar = true;
    ExtensionManager.ImportSettings(settings);
    _settings = ExtensionManager.GetSettings(_ext);
}

You can retrieve these settings back by using GetSingleValue method of the ExtensionSettings object:

protected void BindForm()
{
    Control_width.Text = _settings.GetSingleValue(_width);
    Control_height.Text = _settings.GetSingleValue(_height);
    Control_background.Text = _settings.GetSingleValue(_bgColor);
    // more...
}

And, in your own admin page, you can save settings to Extension Manager like so:

protected void SaveSettings()
{
    _settings.UpdateScalarValue(_width, Control_width.Text);
    _settings.UpdateScalarValue(_height, Control_height.Text);
    _settings.UpdateScalarValue(_bgColor, Control_background.Text);
    // more...
    ExtensionManager.SaveSettings(_ext, _settings);
}

mp3-settings.png

This way, you not forced into using standard default settings page, and yet you can use Extension Manager as your data access layer to make your custom admin code cleaner and simpler.

Happy coding in the New Year!

About RTUR.NET

This site is all about developing web applications with focus on designing and building open source blogging solutions. Technologies include ASP.NET Core, C#, Angular, JavaScript and more.