如果循环播放,音乐不会停止(true) [英] Music doesn't stop if Looping(true)

查看:100
本文介绍了如果循环播放,音乐不会停止(true)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在eclipse中使用MediaPlayer,我发现如果我循环播放这首歌,我想在需要时不能暂停它.为了清楚起见,我将向您显示代码.

i'm currently working with MediaPlayer in eclipse, i found out that if i'm looping the song i can not Pause it when i want. To be clear i will show you the code.

在OnCreate部分

in OnCreate section

    ToggleButton unu = (ToggleButton)this.findViewById(R.id.button1);
    final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.ss);
    unu.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            // If the music is playing
            if(mp1.isPlaying())
                // Pause the music player
                mp1.pause();
            // If it's not playing
            else
                // Resume the music player
                mp1.setLooping(true);
                mp1.start();
        }
    });

我为什么不能暂停它的任何想法? 我正在尝试像这样的东西

Any ideas why i can't pause it? i was trying something like this

            if(mp1.isPlaying())
                // Pause the music player
                mp1.pause();
                mp1.setLooping(false);
            // If it's not playing
            else
                // Resume the music player
                mp1.setLooping(true);
                mp1.start();

它给了我错误消息:令牌"else"上的语法错误,请删除该令牌

it gives me error saying: Syntax error on token "else", delete this token

推荐答案

如Nfear所说的括号丢失了

as Nfear said brackets where missing

       if(mp1.isPlaying()) {
            // Pause the music player
            mp1.pause();
            mp1.setLooping(false); }
        // If it's not playing
        else {
            // Resume the music player
            mp1.setLooping(true);
            mp1.start(); }

添加括号解决了错误

这篇关于如果循环播放,音乐不会停止(true)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆