Welcome to K230 Vision Module repository
4. Play Video
Play Video
Introduction to the results of routine experiments
In this section, we will learn how to use K230 to play MP4 format videos.
The example code of this section is located in: [Source code/10.Media/04.play_video.py]
We use CanMV IDE to open the sample code and connect K230 to the computer via USB.
Click the Run button in the lower left corner of CanMV IDE, and K230 will start playing the video (the default video is [/data/video/video.mp4])
Note 1: The current version of K230 can only play videos with audio format g711. If the video cannot be played, it is likely that the audio in your video file is in the mainstream ACC format.
Note 2: The video recorded using the example code in the previous section can be played
Note 3: The sound of the currently recorded video will be intermittent when playing. This problem will be fixed in subsequent versions.
Code Analysis
Let's analyze the structure of this MP4 player code:
- Overall architecture
It mainly contains two functions:
player_event: Player event callback processingplay_mp4_test: Core MP4 playback function
Global state management: using
start_playvariables to track playback state
- Player initialization and configuration
xxxxxxxxxxplayer = Player(Display.ST7701) # 使用ST7701 LCD屏作为输出显示,最大分辨率640*480 Use the ST7701 LCD screen as the output display, with a maximum resolution of 640*480player = Player(Display.ST7701) # 使用ST7701 LCD屏作为输出显示,最大分辨率640*480 load mp4 fileplayer.set_event_callback(player_event) # 设置播放器事件回调函数 Set the player event callback function- Event handling mechanism
xxxxxxxxxx