实验六 在应用程序中播放音频和视频

【目的】

    实现在应用程序中处理音频和视频。

【要求】

   1.实现播放音频,音频播放控制;

   2.实现播放视频,视频播放控制;

   3.使用Service服务播放项目源文件中的音乐。

【原来】

   Android多媒体处理机制。

【过程】

   1.新建工程Mediaplayer;

   2.修改布局文件activity_main,添加videoview.xml文件;

   3.修改MainActivity.java,新建VideoActivity.java;

   4.新建MusicService类,使用Service 服务器播放项目源文件中的音乐,实现后台继续播放音频。

   5.代码

   activity_main.xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#bbbbbb"
    tools:context=".MainActivity" 
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button4"
        android:layout_alignRight="@+id/button6"
        android:gravity="center"
        android:text="测试多媒体播放"
        android:textSize="45px" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_alignRight="@+id/button6"
        android:layout_below="@+id/textView1"
        android:text="播放源文件中的音乐" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignRight="@+id/button6"
        android:layout_below="@+id/button1"
        android:text="播放本地文件系统的音乐" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignRight="@+id/button6"
        android:layout_below="@+id/button2"
        android:text="播放网络上的音乐" />

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button5"
        android:layout_alignBottom="@+id/button5"
        android:layout_toRightOf="@+id/button5"
        android:text="退出" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button3"
        android:layout_toLeftOf="@+id/button5"
        android:text="停止播放" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button3"
        android:layout_centerHorizontal="true"
        android:text="播放视屏" />

</RelativeLayout>

videoview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#bbbbbb"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="match_parent"
        android:layout_height="500px" />
    
</LinearLayout>

MainActivity.java代码

package com.example.mediaplayer;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
    private TextView tv;
    private Button source,local,net,stopbtn,startbtn,exitbtn;
    private MediaPlayer soutceMP = new MediaPlayer();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        source=(Button)findViewById(R.id.button1);
        local=(Button)findViewById(R.id.button2);
        net=(Button)findViewById(R.id.button3);
        stopbtn=(Button)findViewById(R.id.button4);
        startbtn=(Button)findViewById(R.id.button5);
        exitbtn=(Button)findViewById(R.id.button6);
        tv=(TextView)findViewById(R.id.textView1);
        final Intent startsv  = new Intent();
        
        source.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                startsv.setClass(MainActivity.this, MusicService.class);
            }
        });
        local.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            }
        });
        net.setOnClickListener(new OnClickListener() {    
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            }
        });
        stopbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub    
            }
        });
        startbtn.setOnClickListener(new OnClickListener() {        
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub    
            }
        });
        exitbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}

 

【运行结果】

【心得体会】

     通过这次实验,学会了如何实现在应用程序中处理音频和视频。

转载于:https://www.cnblogs.com/jun-28blog/p/5420083.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
北航电气实验的FPGA程序是指在北京航空航天大学电气工程与自动化学院的实验课程,学生通过使用FPGA(Field Programmable Gate Array)进行实验设计和开发相应的硬件程序。FPGA是一种可编程逻辑器件,可以通过在其内部配置不同的逻辑网元和连接关系来实现各种不同的电路功能。 在北航电气实验,学生通过FPGA的使用,可以进行数字电路设计、系统控制、信号处理等相关实验。学生首先需要了解FPGA的基本概念和原理,掌握FPGA的编程语言,如VHDL(Very High-Speed Integrated Circuit Hardware Description Language)或Verilog等。然后,他们可以使用相应的开发工具,比如Xilinx ISE或Quartus II等,在计算机上编写FPGA程序,并将其下载到FPGA芯片上。 通过FPGA程序设计,学生可以实现各种数字电路的功能,如加法器、多路选择器、计数器等。此外,还可以设计复杂的数字系统,如控制器、处理器、通信传输等。学生还可以通过FPGA程序来进行信号处理和图像处理等应用,如音频等处理。 北航电气实验的FPGA程序设计使学生能够在实践巩固所学的理论知识,并培养他们的创新意识和实验能力。通过实验,学生可以深入了解数字电路原理、底层硬件设计和实现,提高他们的问题解决和团队合作能力。 总而言之,北航电气实验的FPGA程序设计是一种基于FPGA芯片的数字电路设计和开发实验,旨在培养学生的实践能力和创新精神,并提高他们对数字电路和系统的理解和应用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值