Python_ more than 10 lines of code to implement a simple player

Source: Internet
Author: User

Python20 Line code implementation simple player
    1. Introduction to the Player
      Player everyone is not unfamiliar, we listen to music, we watch the video will be used. So what are the functions that the player implements? A player generally completes the following steps:

      • Read files (including audio files and video files)
      • Determine the file type (video and audio format before Chavanbe)
      • Decoding according to the different file types (the volume of the streaming media is too large, generally compressed, and the compression of the standard and format are various)
      • Ensure that the sound and picture synchronization (screen and video out of sync is not very uncomfortable)
      • Decoded image rendering to display devices (such as monitors, different graphics cards and hardware drivers also before Chavanbe)
      • Decoded image rendering to a sound device (such as a sound card)
      There is no feeling so complicated. Yes, it's the complexity behind a video playback, but it's simple for our users. This is also our common pursuit of a product philosophy, the complexity left behind, the simple presentation to the user.

2. Use Python to simply implement the player '

After touching python, discovering its strengths, combined with its own technical direction, the simple implementation of a player, it can be said that such a combination of the complexity left to the programmer is further reduced.

Of course, if you want to fully understand this program, you may need to have a certain premise:

    • You have a simple Python base, you don't need to be proficient, you can get started quickly
    • You have simple graphic image of the foundation, read my blog of you, basically have this ability (haha)

Again, the development environment required for this program:

    • Python development environment, at least 3.6, IDE you can use anything, Vscode, pycharm and so on
    • You need to install the Pyglet Python Library: The install command is simple.pip install pyglet
    • At the same time you need to install Avbin Dynamic Library, which is a multimedia decoding library used by Pyglet, move your finger, Baidu or Google, and then install
    • You need to install the Pyinstaller Library: The Install command is also simplepip install PyInstaller
    • It's best to find a player icon: Mylayer.ico
    • Prepare a video of a test

Well, when the environment is ready, the next is the legendary more than 10 lines of code:

import pygletwindow = pyglet.window.Window(resizable=True)@window.eventdef on_draw():    player.get_texture().blit(0, 0)if __name__ == "__main__":    player = pyglet.media.Player()    source = pyglet.media.load("F:\\FFOutput\\parent.vob")    player.queue(source)    player.play    pyglet.app.run()

A description of this code:

    • The path of the file must be written right oh, that's the path to your test video.
    • This is a simple version, so only the playback, and no control, such as pause, playback and other options
    • Don't forget to write pyglet.app.run() this is the starting point of the program event loop, huh?

3. Generating EXE files
pyinstaller player.py -F --icon=player.ico

Attention:

    • The player.py here is the name of the Python file we created, and you can get a more cool
    • The Player.ico here is the icon of the EXE file we generated.
    • The Pyinstaller here is the executable program of the Pyinstaller package in our environment preparation, which is used to package Python programs, is there a strong

十几行代码,实现一个简单播放器,有没有很简单。可以尝试一下看看效果哦

Python_ more than 10 lines of code to implement a simple player

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.