简体   繁体   English

通知有效,但无法播放附加到它的音频文件(.mp3)

[英]Notification works but doesn't play the audio file (.mp3) attached to it

Hey guys so iv'e recently been trying to program a timer where once the timer hits 0 a notification appears telling the user what happened and will play a sound along with it. 嗨,大家好,我最近一直在尝试对计时器进行编程,一旦计时器达到0,就会出现一条通知,告诉用户发生了什么事,并随之播放声音。 Ive been able to get my default phone notification sound to work but i cant seem to get this custom sound to work. 我已经能够使我的默认电话通知声音正常工作,但是我似乎无法使这种自定义声音正常工作。 Heres my code am I missing something? 这是我的代码,我缺少什么吗?

Uri sound = Uri.parse("android.resource://com.example.jmac.spawny"+R.raw.fresh_overs);
    PendingIntent intent = PendingIntent.getActivity(this, 100, new Intent(this, Guardian.class), 0);

    NotificationCompat.Builder nb = new NotificationCompat.Builder(this);
    nb.setSmallIcon(R.drawable.spawnymascot);
    nb.setSound(sound);
    nb.setContentTitle("Overs Up Bro!");
    nb.setContentText("Click to return to Guardian Screen");
    nb.setContentIntent(intent);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(100, nb.build());

您没有使用斜杠将包名称与资源ID分开:

Uri sound = Uri.parse("android.resource://com.example.jmac.spawny/"+R.raw.fresh_overs);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM