SOL9 Sample: SolMediaPlayer

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * SolMediaPlayer.cpp 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL9 2.0
// 2011/02/21 This is a sample program to use SOL::MediaPlayer to embed a 
// WindowsMediaPlayer into your own application window.

#include <sol\ApplicationView.h>
#include <sol\ole\MediaPlayer.h>
#include <sol\FileDialog.h>
#include <sol/Stdio.h>
#include "resource.h"

namespace SOL {

/**
 * class SolMediaPlayer
 */
class SolMediaPlayer :public ApplicationView {
private:
    MediaPlayer mediaPlayer;
    FileDialog fileDialog;

public:
    /**
     * Constructor
     */
    SolMediaPlayer(Application& applet, const TCHAR* name, Args& args)
    :ApplicationView(applet, name, 
            args.set(XmNbackground, (ulong)(COLOR_BTNFACE+1))    )
    {
        Args ar;

        ar.set(XmNclassStyle, CS_DBLCLKS);
        ar.set(XmNstyle, WS_CHILD|WS_VISIBLE|WS_CHILD | WS_VISIBLE);
        mediaPlayer.create(this, _T(""), ar);

        ar.reset();
        ar.set(XmNfilter, _T("Windows Media(*.wmv *.wma *.mp3)\0 *.wmv;*.wma;*.mp3\0"));
        fileDialog.create(this, _T("FileSelection"), ar);

        addCallback(XmNmenuCallback, IDM_OPEN, this, (Callback)&SolMediaPlayer::open, NULL);

        addCallback(XmNmenuCallback, IDM_EXIT, this, (Callback)&SolMediaPlayer::exit, NULL);
        addCallback(XmNmenuCallback, IDM_VERSION, this, (Callback)&SolMediaPlayer::version, NULL);

        addEventHandler(WM_SIZE, this, (Handler)&SolMediaPlayer::size, NULL);
        addEventHandler(WM_CLOSE, this, (Handler)&SolMediaPlayer::close, NULL);

        restorePlacement();
    }

private:
    /**
     * Callback for [Open] menu.
     */
    void    open(Action& action) {
        Args ar;
        
        TCHAR dir[MAX_PATH];
        memset(dir, (TCHAR)0, SizeOf(dir));

        //Restore a previously selected folder from a registry(profile of 
        //this application) for fileDialog
        if (restoreFileFolder(dir, SizeOf(dir))) {
            ar.set(XmNdirectory, dir);
            fileDialog.setValues(ar);
        }
    
        if(fileDialog.open()){
            TCHAR title[MAX_PATH];
            TCHAR* filename = fileDialog.getFileName();
            TCHAR* ftitle = fileDialog.getFileTitle();
        
            saveFileFolder(filename);
            mediaPlayer.play(filename);

            _stprintf_s(title, SizeOf(title), _T("%s - SolMediaPlayer"), filename);

            setText(title);
        }
    }

public:
    /**
     * WM_SIZE event handler.
     */
    long size(Event& event)
    {
        LPARAM l = event.getLParam();
        mediaPlayer.reshape(0, 0, LOWORD(l), HIWORD(l));
        return 0;
    }

public:
    long close(Event& event)
    {
        savePlacement();
        return defaultProc(event);
    }

private:
    void version(Action& action)
    {
        showMessageDialog(_T("Version"),
            _T("SolMediaPlayer Version 1.0.0.1\r\nCopyright(C) 2011 Antillia.com"),
            MB_OK|MB_ICONINFORMATION);
    }

};

}

//////////////////////////////////////
// SolMediaPlayer.exe
//
//    Program entry point.
void    Main(int argc, TCHAR** argv)
{
    OleInitialize(NULL);

    try {
        const String appClass = "SolMediaPlayer";
        Application applet(appClass, argc, argv);

        Args args;
        args.set(XmNclassStyle, CS_DBLCLKS);
        args.set(XmNexStyle, WS_EX_CONTROLPARENT|WS_EX_TRANSPARENT);

        SolMediaPlayer browser(applet, appClass, args);
        browser.realize();

        applet.run();
    } catch (...) {

    }
    OleUninitialize();
}


Last modified: 25 Feb 2011

Copyright (c) 2011 Antillia.com ALL RIGHTS RESERVED.