Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6190981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:41:01+00:00 2026-05-24T02:41:01+00:00

I just copy pasted this media player in python .When I am running this

  • 0

I just copy pasted this media player in python .When I am running this using the command python mediaplayer.py (mediaplayer.py is my filwename) there is no output .Can anyone tell why?

import os
import time
import wx
import MplayerCtrl as mpc
import wx.lib.buttons as buttons

dirName = os.path.dirname(os.path.abspath(__file__))
bitmapDir = os.path.join(dirName,'bitmaps')

class Frame(wx.Frame):

def __init__(self,parent,id,title,mplayer):
    wx.Frame.__init__(self,parent,id,title)
     self.panel = wx.Panel(self)

    sp = wx.StandardPaths.Get()
    self.currentFolder = sp.GetDocumentsDir()
    self.currentVolume = 50

    self.create_menu()

    # create sizers
    mainSizer = wx.BoxSizer(wx.VERTICAL)
    controlSizer = self.build_controls()
    sliderSizer = wx.BoxSizer(wx.HORIZONTAL)

    self.mplayer = mpc.MplayerCtrl(self.panel, -1, mplayer)
    self.playbackSlider = wx.Slider(self.panel, size=wx.DefaultSize)
    sliderSizer.Add(self.playbackSlider, 1, wx.ALL|wx.EXPAND, 5)

    # create volume control
    self.volumeCtrl = wx.Slider(self.panel)
    self.volumeCtrl.SetRange(0, 100)
    self.volumeCtrl.SetValue(self.currentVolume)
    self.volumeCtrl.Bind(wx.EVT_SLIDER, self.on_set_volume)
    controlSizer.Add(self.volumeCtrl, 0, wx.ALL, 5)

    # create track counter
    self.trackCounter = wx.StaticText(self.panel, label="00:00")
    sliderSizer.Add(self.trackCounter, 0, wx.ALL|wx.CENTER, 5)

    # set up playback timer
    self.playbackTimer = wx.Timer(self)
    self.Bind(wx.EVT_TIMER, self.on_update_playback)

    mainSizer.Add(self.mplayer, 1, wx.ALL|wx.EXPAND, 5)
    mainSizer.Add(sliderSizer, 0, wx.ALL|wx.EXPAND, 5)
    mainSizer.Add(controlSizer, 0, wx.ALL|wx.CENTER, 5)
    self.panel.SetSizer(mainSizer)

    self.Bind(mpc.EVT_MEDIA_STARTED, self.on_media_started)
    self.Bind(mpc.EVT_MEDIA_FINISHED, self.on_media_finished)
    self.Bind(mpc.EVT_PROCESS_STARTED, self.on_process_started)
    self.Bind(mpc.EVT_PROCESS_STOPPED, self.on_process_stopped)

    self.Show()
    self.panel.Layout()

#----------------------------------------------------------------------
def build_btn(self, btnDict, sizer):
    """"""
    bmp = btnDict['bitmap']
    handler = btnDict['handler']

    img = wx.Bitmap(os.path.join(bitmapDir, bmp))
    btn = buttons.GenBitmapButton(self.panel, bitmap=img,
                                  name=btnDict['name'])
    btn.SetInitialSize()
    btn.Bind(wx.EVT_BUTTON, handler)
    sizer.Add(btn, 0, wx.LEFT, 3)

#----------------------------------------------------------------------
def build_controls(self):
    """
    Builds the audio bar controls
    """
    controlSizer = wx.BoxSizer(wx.HORIZONTAL)

    btnData = [{'bitmap':'player_pause.png',
                'handler':self.on_pause, 'name':'pause'},
               {'bitmap':'player_stop.png',
                'handler':self.on_stop, 'name':'stop'}]
    for btn in btnData:
        self.build_btn(btn, controlSizer)

    return controlSizer

#----------------------------------------------------------------------
def create_menu(self):
    """
    Creates a menu
    """
    menubar = wx.MenuBar()
    fileMenu = wx.Menu()
    add_file_menu_item = fileMenu.Append(wx.NewId(), "&Add File", "Add Media File")
    menubar.Append(fileMenu, '&File')

    self.SetMenuBar(menubar)
    self.Bind(wx.EVT_MENU, self.on_add_file, add_file_menu_item)

#----------------------------------------------------------------------
def on_add_file(self, event):
    """
    Add a Movie and start playing it
    """
    wildcard = "Media Files (*.*)|*.*"
    dlg = wx.FileDialog(
        self, message="Choose a file",
        defaultDir=self.currentFolder,
        defaultFile="",
        wildcard=wildcard,
        style=wx.OPEN | wx.CHANGE_DIR
        )
    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath()
        self.currentFolder = os.path.dirname(path[0])
        trackPath = '"%s"' % path.replace("\\", "/")
        self.mplayer.Loadfile(trackPath)

        t_len = self.mplayer.GetTimeLength()
        self.playbackSlider.SetRange(0, t_len)
        self.playbackTimer.Start(100)


#----------------------------------------------------------------------
def on_media_started(self, event):
    print 'Media started!'

#----------------------------------------------------------------------
def on_media_finished(self, event):
    print 'Media finished!'
    self.playbackTimer.Stop()

#----------------------------------------------------------------------
def on_pause(self, event):
    """"""
    if self.playbackTimer.IsRunning():
        print "pausing..."
        self.mplayer.Pause()
        self.playbackTimer.Stop()
    else:
        print "unpausing..."
        self.mplayer.Pause()
        self.playbackTimer.Start()

#----------------------------------------------------------------------
def on_process_started(self, event):
    print 'Process started!'

#----------------------------------------------------------------------
def on_process_stopped(self, event):
    print 'Process stopped!'

#----------------------------------------------------------------------
def on_set_volume(self, event):
    """
    Sets the volume of the music player
    """
    self.currentVolume = self.volumeCtrl.GetValue()
    self.mplayer.SetProperty("volume", self.currentVolume)

#----------------------------------------------------------------------
def on_stop(self, event):
    """"""
    print "stopping..."
    self.mplayer.Stop()
    self.playbackTimer.Stop()

#----------------------------------------------------------------------
def on_update_playback(self, event):
    """
    Updates playback slider and track counter
    """
    try:
        offset = self.mplayer.GetTimePos()
    except:
        return
    print offset
    mod_off = str(offset)[-1]
    if mod_off == '0':
        print "mod_off"
        offset = int(offset)
        self.playbackSlider.SetValue(offset)
        secsPlayed = time.strftime('%M:%S', time.gmtime(offset))
        self.trackCounter.SetLabel(secsPlayed)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:41:02+00:00Added an answer on May 24, 2026 at 2:41 am

    It is not meant to be used as you posted it.

    The class needs to be instantiated, and possibly run in a main loop of some sort.

    In addition, as you can see on the line import MplayerCtrl as mpc, it isn’t a stand-alone.

    Please post at minimum a link to where you downloaded it.

    Also, be aware it appears to be a wrapper around a real media player that implements a wxPython interface, not a full media player, so you’ll still need the actual application (I assume mplayer based on the naming) for it to do anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like copy just file.xml without folder structure using overlays like this: <overlays>
This code is working in another Access db. I just copy pasted the code
Is there any difference between Array.Copy and CopyTo ? Are they just overloaded?
I'm using TortoiseSVN. I just made quite a few changes to my working copy
I think it would be best if I just copy and pasted the code
Ok just to know,I copy-pasted the code from the android website,so I don't think
I've copy pasted this .vimrc into my /etc/vimrc in Fedora 15. Every time I
This is for a homework assignment. I haven't copy-pasted the question below, I made
My PM just stopped by and he wanted a copy of all of our
We just switched to our new website redesign. We have a copy of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.