体育彩票江苏7位数928:Android 4.x 使用MediaPlayer播放音頻(學校作業,備份,音頻已替換為“雞你太美”) ... [復制鏈接]

2019-8-19 15:55
奶油話梅糖 閱讀:398 評論:0 贊:0
Tag:  

体彩江苏7位数18148 www.zyvyo.com

[代碼]xml代碼:

<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
    xmlns:tools="//schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btnPickAudio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="開始播放" />

    <TextView
        android:id="@+id/txvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btnPickAudio"
        android:text="文件名:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/txvUri"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/txvName"
        android:text="路徑:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Spinner
        android:id="@+id/sp_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/btnPickAudio"
        android:entries="@array/music" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/btn_stop"
        android:layout_alignRight="@+id/btn_stop"
        android:layout_below="@+id/txvUri" >

        <TextView
            android:id="@+id/tv_geci"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/txvUri"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </ScrollView>

    <WebView
        android:id="@+id/mt_web_view"
        android:layout_width="200sp"
        android:layout_height="200sp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/btn_stop" />

    <Button
        android:id="@+id/btn_stop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="NMD!快停下!別打籃球了!" />

</RelativeLayout>

[代碼]java代碼:

package com.example.musicplayer;

import java.io.FilenameFilter;
import java.io.IOException;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends Activity {
	private TextView txvName, txvUri, tv_geci;
	private Button btn_start, btn_stop;
	private MediaPlayer mper;
	private int number = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
		// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//強制豎屏
		txvName = (TextView) findViewById(R.id.txvName);
		txvUri = (TextView) findViewById(R.id.txvUri);
		txvUri.setText("ID:" + String.valueOf(R.raw.swin));
		tv_geci = (TextView) findViewById(R.id.tv_geci);
		btn_stop = (Button) findViewById(R.id.btn_stop);
		btn_start = (Button) findViewById(R.id.btnPickAudio);
		txvName.setText("雞你太美.mp3");
		btn_start.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				number++;
				playFromRaw();
				if (mper.isPlaying()) {
					Toast.makeText(MainActivity.this, "雞已經在太美了",
							Toast.LENGTH_SHORT).show();
				} else {
				}
				txvName.setText("雞你太美" + "x" + number);
				tv_geci.setVisibility(View.VISIBLE);
				tv_geci.setText("只因你太美 baby 只因你太美 baby" + "\n"
						+ "只因你實在是太美 baby 只因你太美 baby" + "\n" + "迎面走來的你讓我如此蠢蠢欲動"
						+ "\n" + "這種感覺我從未有" + "\n"
						+ "Cause I got a crush on you who you" + "\n"
						+ "你是我的我是你的誰" + "\n" + "再多一眼看一眼就會爆炸" + "\n"
						+ "再近一點靠近點快被融化" + "\n" + "想要把你占為己有baby bae" + "\n"
						+ "不管走到哪里都會想起的人是你 you you" + "\n" + "我應該拿你怎樣" + "\n"
						+ "uh 所有人都在看著你" + "\n" + "我的心總是不安" + "\n"
						+ "oh 我現在已病入膏肓" + "\n" + "eh eh 難道真的因為你而瘋狂嗎" + "\n"
						+ "我本來不是這種人" + "\n" + "因你變成奇怪的人" + "\n" + "第一次呀變成這樣的我"
						+ "\n" + "不管我怎么去否認" + "\n" + "只因你太美 baby 只因你太美 baby"
						+ "\n" + "只因你實在是太美 baby 只因你太美 baby" + "\n"
						+ "oh eh oh 現在確認地告訴我" + "\n" + "oh eh oh 你到底屬于誰" + "\n"
						+ "oh eh oh 現在確認地告訴我" + "\n"
						+ "oh eh oh 你到底屬于誰 就是現在告訴我" + "\n"
						+ "跟著這節奏 緩緩 make wave" + "\n"
						+ "甜蜜的奶油 it's your birthday cake" + "\n"
						+ "男人們的 game call me 你戀人" + "\n"
						+ "別被欺騙愉快的 I wanna play" + "\n" + "我的腦海每分每秒只為你一人沉醉"
						+ "\n" + "最迷人讓我神魂顛倒是你身上香水" + "\n"
						+ "oh right baby I'm fall in love with you" + "\n"
						+ "我的一切你都拿走只要有你就已足夠" + "\n" + "我到底應該怎樣" + "\n"
						+ "uh 我心里一直很不安" + "\n" + "其他男人們的視線" + "\n"
						+ "Oh 全都只看向你的臉" + "\n" + "Eh eh 難道真的因為你而瘋狂嗎" + "\n"
						+ "我本來不是這種人" + "\n" + "因你變成奇怪的人" + "\n" + "第一次呀變成這樣的我"
						+ "\n" + "不管我怎么去否認" + "\n" + "只因你太美 baby 只因你太美 baby"
						+ "\n" + "只因你實在是太美 baby 只因你太美 baby" + "\n"
						+ "我愿意把我的全部都給你" + "\n" + "我每天在夢里都夢見你還有我閉著眼睛也能看到你"
						+ "\n" + "現在開始我只準你看我" + "\n"
						+ "I don't wanna wake up in dream 我只想看你這是真心話"
						+ "\n" + "只因你太美 baby 只因你太美 baby" + "\n"
						+ "只因你實在是太美 baby 只因你太美 baby" + "\n"
						+ "oh eh oh 現在確認的告訴我" + "\n" + "oh eh oh 你到底屬于誰" + "\n"
						+ "oh eh oh 現在確認的告訴我" + "\n" + "oh eh oh 你到底屬于誰就是現在告訴我");
			}
		});
		btn_stop.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mper.isPlaying()) {
					mper.stop();
					Toast.makeText(MainActivity.this,
							"如果你點開始點多了,是停不下來的.....(我也不知道為什么不行)",
							Toast.LENGTH_SHORT).show();

				} else {
					Toast.makeText(MainActivity.this, "先開始播放唄?",
							Toast.LENGTH_SHORT).show();
				}
			}
		});

	}

	private void playFromRaw() {
		mper = MediaPlayer.create(this, R.raw.swin);
		mper.start();
	}
}



我來說兩句
您需要登錄后才可以評論 登錄 | 立即注冊
facelist
所有評論(0)
領先的中文移動開發者社區
18620764416
7*24全天服務
意見反?。[email protected]

掃一掃關注我們

Powered by Discuz! X3.2© 2001-2019 Comsenz Inc.( 体彩江苏7位数18148 )