急急急!!!本人新手,急求大佬帮忙看一下这是什么问题?

用Android studio 2.1写的
如题,简单的调用一个Media Player来播放一首歌曲,语法应该没啥错误,但是在模拟机上运行的时候,程序可以打开,但是按播放按钮的时候就这样了。(歌曲也放在路径下了)在这里插入图片描述
在这里插入图片描述
代码如下,大佬们帮看看到时是代码的问题,还是缺什么东西没装?

package com.example.dy.musicplayer;

    import android.media.MediaPlayer;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.SeekBar;
    import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Button startBtn;
SeekBar positionBar;
SeekBar volumeBar;
TextView elapsedTimeLabel;
TextView remainingTimeLabel;
MediaPlayer mp;
int totalTime;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    startBtn = (Button) findViewById(R.id.startBtn);
    elapsedTimeLabel = (TextView) findViewById(R.id.elapsedTimeLabel);
    remainingTimeLabel = (TextView) findViewById(R.id.remainingTimeLabel);


    //Media Player
    mp = MediaPlayer.create(this, R.raw.music);
    mp.setLooping(true);
    mp.seekTo(0);
    mp.setVolume(0.5f, 0.5f);
    totalTime = mp.getDuration();


    //position Bar
    positionBar = (SeekBar) findViewById(R.id.positionBar);
    positionBar.setMax(totalTime);


    //Volume Bar
    volumeBar = (SeekBar) findViewById(R.id.volumeBar);

}

public void StartBtnClick(View view){

    if(!mp.isPlaying()){
        //stoping

        mp.start();

        startBtn.setBackgroundResource(R.drawable.stop);

    }else{
        //Palying
        mp.pause();
        startBtn.setBackgroundResource(R.drawable.start);
    }
}

}

下面这是界面布局

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:src="@drawable/test"
    android:layout_marginTop="20dp" />


<SeekBar
    android:id="@+id/positionBar"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
   <TextView
       android:id="@+id/elapsedTimeLabel"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="0:11"


       android:layout_marginLeft="40dp" />

    <TextView
        android:id="@+id/remainingTimeLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-1:49"
        android:layout_marginLeft="240dp"/>
</LinearLayout>

<Button
    android:id="@+id/startBtn"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:background="@drawable/start"
    android:layout_marginTop="40dp"
    android:onClick="startBtnClick"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="40dp"
    android:gravity="center">
    <ImageButton
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:src="@drawable/sound"/>
    <SeekBar
        android:id="@+id/volumeBar"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:progress="50"
        android:max="100"/>
    <ImageView
        android:layout_width="26dp"
        android:layout_height="26dp"
        android:src="@drawable/sound2"/>
</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值