android 調用系統的音樂和視頻播放器


package com.eboy.testsystemaudiovideo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public  class MainActivity  extends Activity {

    @Override
     public  void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button btnAudio = (Button)  this.findViewById(R.id.button1);        
        
        btnAudio.setOnClickListener( new OnClickListener() {
            
            @Override
             public  void onClick(View v) {
                Intent it =  new Intent(Intent.ACTION_VIEW);
                it.setDataAndType(Uri.parse("file://" + Environment.getExternalStorageDirectory() + "/a.MP3"), "audio/MP3");
                startActivity(it);            
            }
        });
        
        Button btnVideo = (Button)  this.findViewById(R.id.button2);
        
        btnVideo.setOnClickListener( new OnClickListener() {
            
            @Override
             public  void onClick(View v) {
                Intent intent =  new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory() + "/3.mp4"), "video/mp4");
                startActivity(intent);
            }
        });
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM