如何使用Applescript和Java在iTunes中播放歌曲预览?

时间:2018-11-30 03:11:45

标签: java applescript 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 /标题?

1 个答案:

答案 0 :(得分:0)

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