【问题标题】:Fatal Python error: (pygame parachute) Segmentation Fault using pygame.midi致命的 Python 错误:(pygame parachute) Segmentation Fault using pygame.midi
【发布时间】:2020-01-09 11:49:15
【问题描述】:

我一直致力于在 pygame 中播放 MIDI 文件,但一直遇到这个错误。

致命的 Python 错误:(pygame parachute) Segmentation Fault

Python 运行时状态:已初始化

这是我的代码:

import pygame.midi
pygame.midi.init()
device = pygame.midi.get_default_output_id()
player = pygame.midi.Output(0)

错误被突出显示为最后一行的问题,但我不完全确定它有什么问题。

谢谢!

【问题讨论】:

    标签: python pygame midi


    【解决方案1】:

    我认为这是 Pygame 中的一个错误,但 tracker 似乎没有任何匹配项。我可以用 PyGame 1.9.4.post1 复制这个问题。

    问题的原因是调用pygame.midi.Output(),我对此进行了一些不同的调用,指定不同的参数会产生不同的错误 - 有时在调用时,但有时在关机时。

    这是一种解决方法,而不是解决方案 - 但您真的需要调用此函数吗?没有它,基本的 MIDI 功能似乎也可以工作。下面的代码播放一个 MIDI 文件,然后干净地退出。

    import sys
    import pygame
    import pygame.midi
    
    pygame.init()
    pygame.midi.init()
    pygame.mixer.init()
    
    midi_file = "popcorn.mid"
    pygame.mixer.music.load( midi_file )
    pygame.mixer.music.play()
    device = pygame.midi.get_default_output_id()
    device_info = pygame.midi.get_device_info( device )
    print( "MIDI Device: " + str( device ) )
    print( "Device Info: " + str( device_info ) )
    #player = pygame.midi.Output( device, buffer_size=4096 )
    
    clock = pygame.time.Clock()
    while pygame.mixer.music.get_busy():
        pygame.time.delay( 1500 )
        print("?", end='')
        sys.stdout.flush()   # just ensure the tick-mark is printed in-time
    
    pygame.mixer.music.stop()
    pygame.quit()
    

    也许是 PyGame 的更高版本 - 甚至可能是(即将推出的?)SDL2 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-17
      • 1970-01-01
      • 2022-12-27
      • 2018-08-15
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-01
      相关资源
      最近更新 更多