Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module player;
- import std.stdio;
- import std.utf;
- import glib.CharacterSet;
- import gdk.Event;
- import gtk.FileChooserDialog;
- import gtk.Main;
- import gtk.MainWindow;
- import gtk.Toolbar;
- import gtk.ToolButton;
- import gtk.VBox;
- import gtk.Widget;
- import gstreamer.gstreamer;
- import gstreamer.Element;
- import gstreamer.ElementFactory;
- import gstreamer.Pipeline;
- class Player
- {
- void openFile(string filename)
- {
- writeln(filename);
- pipeline = new Pipeline("audio-player");
- source = ElementFactory.make("filesrc", "file-source");
- decoder = ElementFactory.make("mad", "mad");
- conv = ElementFactory.make("audioconvert", "converter");
- sink = ElementFactory.make("autoaudiosink", "auto-output");
- source.location(filename);
- pipeline.add(source);
- pipeline.add(decoder);
- pipeline.add(conv);
- pipeline.add(sink);
- source.link(decoder);
- decoder.link(conv);
- conv.link(sink);
- pipeline.setState(GstState.PLAYING);
- }
- void stop()
- {
- if (pipeline)
- pipeline.setState(GstState.NULL);
- }
- Pipeline pipeline;
- Element source, decoder, conv, sink;
- }
- class Application: MainWindow
- {
- Player player;
- VBox vbox;
- Toolbar toolbar;
- ToolButton openButton;
- ToolButton stopButton;
- this()
- {
- super("Player");
- setDefaultSize(320, 240);
- addOnDelete(&onExit);
- player = new Player();
- toolbar = new Toolbar();
- openButton = new ToolButton(StockID.OPEN);
- openButton.setIsImportant(true);
- openButton.addOnClicked((ToolButton b)
- {
- open();
- });
- stopButton = new ToolButton(StockID.STOP);
- stopButton.setIsImportant(true);
- stopButton.addOnClicked((ToolButton b)
- {
- player.stop();
- });
- toolbar.insert(openButton, -1);
- toolbar.insert(stopButton, -1);
- vbox = new VBox(false, 0);
- vbox.packStart(toolbar, false, false, 0);
- add(vbox);
- showAll();
- }
- bool onExit(Event event, Widget widget)
- {
- writeln("Application terminated");
- return false;
- }
- string localeToUnicode(string input)
- {
- uint bytesRead, bytesWritten;
- string res = CharacterSet.localeToUtf8(
- input, input.length, bytesRead, bytesWritten);
- validate(res);
- return res;
- }
- void open()
- {
- string filename;
- bool goingToOpen = false;
- auto fs = new FileChooserDialog("File Selection", this, FileChooserAction.OPEN,
- ["Open", "Cancel"], [ResponseType.ACCEPT, ResponseType.CANCEL]);
- if (fs.run() == ResponseType.ACCEPT)
- {
- filename = localeToUnicode(fs.getFilename());
- goingToOpen = true;
- }
- fs.destroy();
- if (goingToOpen)
- {
- player.openFile(filename);
- }
- }
- }
- void main(string[] args)
- {
- GStreamer.init(args);
- Main.init(args);
- auto app = new Application();
- Main.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement