首页 > 解决方案 > 如何使用 Applescript 和 Java 在 iTunes 中播放歌曲预览?

问题描述

我经常使用 iTunes API 来搜索歌曲,我希望用户能够选择一个选项来在 iTunes 中播放歌曲预览。

目前,以下将简单地打开 iTunes:

public class PlayMedia {

public PlayMedia()
  {
    Runtime runtime = Runtime.getRuntime();
    String[] args = { "osascript", "-e", "tell application \"iTunes\" to play"};

    try
    {
      Process process = runtime.exec(args);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
}

public static void main(String[] args) throws IOException, JSONException {
    new PlayMedia();
}

我如何对此进行扩展以传递歌曲 ID/标题?

标签: javaapplescriptitunes

解决方案


String[] args = {"osascript", "-e", "on run {arg1, arg2,…}", 
                              "-e", "  tell application \"iTunes\" to …", 
                              "-e", "end run", 
                              "--",
                              arg1, arg2, …};

推荐阅读