Wednesday, February 13, 2019

Koding Membuat Media Pembelajaran Pemutar Musik


Koding Java Membuat Menu

package com.HmI;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class kumpulanlagu extends Activity implements OnItemClickListener {
    /** Called when the activity is first created. */
       ListView lv;
       String[] menu= {"Hymne HmI","Darah Juang","Hijau Hitam","Bergerak","Buruh Tani",
                     "Jayalah Himpunan","Jiwa Pejuang","Kaukan Mengerti","Mars Demonstrasi",
                     "Mars Kohati","Mars Maperca","Mars BPL","Nongkrong","Pandal","Sebuah Impian","Tanpa Lakon",
                     "Totalitas Perjuangan","Tragedi"};
       ArrayAdapter<String>adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kumpulanlaguu);
        lv=(ListView)findViewById(R.id.listView1);
        adapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,menu);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(this);
                     }
       public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
              // TODO Auto-generated method stub
              if (menu [arg2].toString().equals("Hymne HmI")){
                     Intent list1 = new Intent(getApplicationContext(), Hymne.class);
                     startActivity(list1);
              } else if (menu[arg2].toString().equals("Darah Juang")){
                     Intent list2 = new Intent(getApplicationContext(),DarahJuang.class);
                     startActivity(list2);
              } else if (menu [arg2].toString().equals("Hijau Hitam")){
                     Intent list3 = new Intent(getApplicationContext(), HijauHitam.class);
                     startActivity(list3);
              } else if (menu [arg2].toString().equals("Bergerak")){
                     Intent list4 = new Intent(getApplicationContext(), bergerak.class);
                     startActivity(list4);
              } else if (menu [arg2].toString().equals("Buruh Tani")){
                     Intent list5 = new Intent(getApplicationContext(), buruhrani.class);
                     startActivity(list5);
              } else if (menu [arg2].toString().equals("Jayalah Himpunan")){
                     Intent list6 = new Intent(getApplicationContext(), Jayalahhimpunan.class);
                     startActivity(list6);
              } else if (menu [arg2].toString().equals("Jiwa Pejuang")){
                     Intent list7 = new Intent(getApplicationContext(), Jiwapejuang.class);
                     startActivity(list7);
              } else if (menu [arg2].toString().equals("Kaukan Mengerti")){
                     Intent list8 = new Intent(getApplicationContext(), Kaukanmengerti.class);
                     startActivity(list8);
              } else if (menu [arg2].toString().equals("Mars Demonstrasi")){
                     Intent list9 = new Intent(getApplicationContext(), Marsdemonstran.class);
                     startActivity(list9);
              } else if (menu [arg2].toString().equals("Mars Kohati")){
                     Intent list10 = new Intent(getApplicationContext(), Marskohati.class);
                     startActivity(list10);
              } else if (menu [arg2].toString().equals("Mars Maperca")){
                     Intent list11 = new Intent(getApplicationContext(), Marsmaperca.class);
                     startActivity(list11);
              } else if (menu [arg2].toString().equals("Nongkrong")){
                     Intent list12 = new Intent(getApplicationContext(), Nongkrong.class);
                     startActivity(list12);
              } else if (menu [arg2].toString().equals("Pandal")){
                     Intent list13 = new Intent(getApplicationContext(), Pandal.class);
                     startActivity(list13);
              } else if (menu [arg2].toString().equals("Sebuah Impian")){
                     Intent list14 = new Intent(getApplicationContext(), Sebuahimpian.class);
                     startActivity(list14);
              } else if (menu [arg2].toString().equals("Tanpa Lakon")){
                     Intent list15 = new Intent(getApplicationContext(), Tanpalakon.class);
                     startActivity(list15);
              } else if (menu [arg2].toString().equals("Totalitas Perjuangan")){
                     Intent list16 = new Intent(getApplicationContext(), Totalitasperjuangan.class);
                     startActivity(list16);
              } else if (menu [arg2].toString().equals("Tragedi")){
                     Intent list17 = new Intent(getApplicationContext(), Tragedi.class);
                     startActivity(list17);
              } else if (menu [arg2].toString().equals("Mars BPL")){
                     Intent list18 = new Intent(getApplicationContext(), Marsbpl.class);
                     startActivity(list18);
                    
       }
             
              }
}

xml = membuat menu
<?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="#00aa00"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" >
    </ListView>

</LinearLayout>
Koding Java Memutar Lagu
import android.app.Activity;
import android.app.AlertDialog;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Hymne extends Activity implements OnClickListener, OnCompletionListener {
       private ImageButton play;
       private ImageButton pause;
       private ImageButton stop;
       private MediaPlayer mp;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hymne);
        play=(ImageButton)findViewById(R.id._play);
              pause=(ImageButton)findViewById(R.id._pause);
              stop=(ImageButton)findViewById(R.id._stop);
             
             
             
             
       
             
              play.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View view) {
                           play();
                     }
              });
             
              pause.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View view) {
                           pause();
                     }
              });
             
              stop.setOnClickListener(new View.OnClickListener() {
                     public void onClick(View view) {
                           stop();
                     }
              });
             
              setup();
                
             
       
       }
      
       @Override
       public void onDestroy() {
              super.onDestroy();
             
              if (stop.isEnabled()) {
                     stop();
              }
       }
      
       public void onCompletion(MediaPlayer mp) {
              stop();
       }
      
      
      
       private void play() {
              mp.start();
             
              play.setEnabled(false);
              pause.setEnabled(true);
              stop.setEnabled(true);
       }
      
       private void stop() {
              mp.stop();
              pause.setEnabled(false);
              stop.setEnabled(false);
             
              try {
                     mp.prepare();
                     mp.seekTo(0);
                     play.setEnabled(true);
              }
              catch (Throwable t) {
                     goBlooey(t);
              }
       }
      
       private void pause() {
              mp.pause();
             
              play.setEnabled(true);
              pause.setEnabled(false);
              stop.setEnabled(true);
       }
      
       private void loadClip() {
              try {
                     mp=MediaPlayer.create(this, R.raw.hymne);
                     mp.setOnCompletionListener(this);
                    
              }
              catch (Throwable t) {
                     goBlooey(t);
              }
       }
      
      
       private void setup() {
              loadClip();
              play.setEnabled(true);
              pause.setEnabled(false);
              stop.setEnabled(false);
       }
      
       private void goBlooey(Throwable t) {
              AlertDialog.Builder builder=new AlertDialog.Builder(this);
             
              builder
                     .setTitle("Exception!")
                     .setMessage(t.toString())
                     .setPositiveButton("OK", null)
                     .show();
       }

       public void onClick(View v) {
              // TODO Auto-generated method stub
             
       }

   
    }

xml = memutar lagu
<?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="#00aa00"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="67dp"
            android:layout_marginTop="370dp"
            android:text="Play"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ff000000"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="24dp"
            android:layout_marginTop="370dp"
            android:text="Pause"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ff000000"
            android:textSize="20dp" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="370dp"
            android:text="Stop"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#ff000000"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/_play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:src="@drawable/play" />

        <Button
            android:id="@+id/_pause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/pause" />

        <Button
            android:id="@+id/_stop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/stop" />
    </LinearLayout>

</LinearLayout>




No comments:

Post a Comment

Media Pembelajaran Pramuka