zoukankan      html  css  js  c++  java
  • 实验7 BindService模拟通信

    实验报告

    课程名称

    基于Android平台移动互联网开发

    实验日期

    2016年4月22日

    实验项目名称

     BindService模拟通信

    实验地点

    S30010

    实验类型

    □验证型    √设计型    □综合型

    学  时

    2

    一、实验目的及要求(本实验所涉及并要求掌握的知识点)

    1.目的:实现启动端和BindService之间的双向通信

    2.要求:实现从启动端传递一个数据至BindService端;

    实现使用BindService服务播放项目源文件中的音乐;

    实现在启动端通过“增加”和“降低”两个按钮控制音频音量大小。

    实现在启动端通过“暂停”按钮控制音频暂停播放。

    二、实验环境(本实验所使用的硬件设备和相关软件)

    (1)PC机

    (2)操作系统:Windows XP

    (3)软件: Eclipse, JDK1.6,Android SDK,ADT

    三、实验内容及步骤

    1)完善Activity类

    2)新建Service类

    四、实验结果(本实验源程序清单及运行结果或实验结论、实验设计图)

    代码:

    sudoku的musicsetting.xml的代码:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:orientation="vertical" >

     

        <TextView

            android:id="@+id/textView1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="音量" />

     

        <SeekBar

            android:id="@+id/seekBar1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content" />

     

        <ProgressBar

            android:id="@+id/progressBar1"

            style="?android:attr/progressBarStyleHorizontal"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            />

     

        <CheckBox

            android:id="@+id/checkBox1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="静音" />

     

        <TextView

            android:id="@+id/textView2"

            android:layout_width="wrap_content"

            android:layout_height="0dp"

            android:text="" />

     

    </LinearLayout>

    sudoku的musicsetting.java部分代码:

    public class MusicBService extends Service implements MediaPlayer.OnCompletionListener {

       MediaPlayer player;

       private final IBinder binder=new AudioBinder();

        @Override

        public IBinder onBind(Intent arg0) {

            // TODO Auto-generated method stub

            return binder;

        }

        @Override

        public void onCompletion(MediaPlayer player) {

            // TODO Auto-generated method stub

            stopSelf();

        }

        public void onCreate(){

            super.onCreate();

            player=MediaPlayer.create(this, R.raw.model);

            player.setOnCompletionListener(this);

        }

        public int onStartCommand(Intent intent,int flags,int startId){

            if(!player.isPlaying()){

                player.start();

            }

            return START_STICKY;

        }

        public void onDestroy(){

            if(player.isPlaying()){

                player.stop();

            }

            player.release();

        }

        class AudioBinder extends Binder{

            MusicBService getService(){

                return MusicBService.this;

            }

        }

       

        public boolean onUnbind(Intent intent){

            return super.onUnbind(intent);

        }

     

    }

    }

    运行结果:(截图)

    1. sudoku项目效果图:

     

    五、实验总结(对本实验结果进行分析,实验心得体会及改进意见)

    通过这一次的实验,我对service类有了一点点的理解,希望可以越做越好。

    实验评语

     

    实验成绩

     

    指导教师签名:              年   月   日

               
  • 相关阅读:
    6)图[5]最短路径
    6)图[4]关键路径
    6)图[3]拓扑排序算法
    6)图[2]Prim算法[最小生成树]
    Aprori算法[关联规则算法]
    K-Modes算法[聚类算法]
    linux Centos6.7 python交互模式下回退异常问题解决
    Python-面向对象(二)-Day7
    Python-面向对象(一)-Day7
    (error) MISCONF Redis is configured to save RDB snapshots
  • 原文地址:https://www.cnblogs.com/xy1015/p/5451618.html
Copyright © 2011-2022 走看看