播放音乐和视频时是否可以使我的系统不挂起?

Joh*_*ohn 3 video music patch suspend

我的朋友想知道是否有可能获得一个补丁,允许他在使用视频或音乐播放器时将计算机设置为不挂起,包括在 youtube 上?我不介意相同的补丁。

他在 Toshiba 上运行 Ubuntu 11.10。我在 hp 上运行 Ubuntu 11.10 。

小智 5

  1. 安装 xmacro (sudo apt-get install xmacro)

  2. 创建一个名为“myxmacro”的文件并为其提供以下内容:

代码:

MotionNotify 90 90 
MotionNotify 120 120
Run Code Online (Sandbox Code Playgroud)

3. 创建一个文件“no.idle.sh”并使其可执行:

代码:

touch no.idle.sh
chmod +x no.idle.sh
Run Code Online (Sandbox Code Playgroud)

4.4. 创建一个文件“no.idle.sh”并使其可执行: 代码:

touch no.idle.sh
chmod +x no.idle.sh
Run Code Online (Sandbox Code Playgroud)

给它以下内容:

代码

    #!/bin/bash
# No.idle.sh prevents GNOME to turn IDLE 
# if there is any sound sent to speakers
# This script requires the package "xmacro"
# (apt-get install xmacro)
###########################################
# This script requires a textfile called "myxmacro"
# with the following (dummy) content:
# ------------ myxmacro ------------
# MotionNotify 90 90 
# MotionNotify 120 120
# ----------------------------------
# You need to fix the path to "myxmacro" in line 31
#
#############################################

# set Log-File
LOG=/home/YOUR_USERNAME/noidle.log
sound=0
silence=0


while true; do
    sleep 1
    Datum=`date +%d.%m.%Y-%H:%M:%S`    

    # check if sound is sent to speaker    
    if pactl list | grep RUNNING > /dev/null; then
        echo "[$Datum] Sound (Ping: $sound)" >> $LOG
        sound=$((sound+1));
        xmacroplay :0 </path/to/myxmacro
        silence=0
    else
        echo "[$Datum] Silence (Ping: $silence)"    >> $LOG
        silence=$((silence+1));
        sound=0
    fi
    #----------------------------------------------------
done
Run Code Online (Sandbox Code Playgroud)

您需要: - 修复第 18 行中日志文件的路径

  • 修复第 31 行中“myxmacro”的路径

    1. 将脚本“no.idle.sh”添加到您的 GNOME-Startup-Items,以便 no.idle.sh 在每次启动时运行。

完毕。

脚本的作用: 脚本每秒检查一次是否有任何声音发送到扬声器(使用终端命令 pactl list | grep RUNNING)。

如果音乐正在运行,它会模拟鼠标移动(使用 xmacroplay)。这会导致您的 GNOME 会话不会运行 IDLE(因此您的 PC 不会挂起)。

如果没有播放音乐,它什么都不做(因此您的会话可以运行 IDLE,然后暂停)

您可以通过在终端中键入来观看检查音乐的脚本:

tail -f /path/to/noidle.log
Run Code Online (Sandbox Code Playgroud)