Está en la página 1de 6

UNIVERSIDAD DE GUAYAQUIL

FACULTAD DE CIENCIAS MATEMATICAS Y FISICAS


CARRERA DE INGENIERIA EN SISTEMAS COMPUTACIONALES

TAREA:

Unidad No 4 - Sesión No 13: Trabajo Autónomo Aplicación Modificada


Modifique la aplicación sobre Servicios de tal manera que permita
escuchar secuencialmente más de una canción

MATERIA:
ELECTIVA IV

DOCENTE:
Msc. SANTOS DIAZ LILIA BEATRIZ

ESTUDIANTE:
COELLO MOSQUERA SONIA BEATRIZ

PARALELO:
ISI-S-MA-8-6

PERIODO
2020 -2021 CI
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/btnIniciar"
android:layout_width="150dp"
android:layout_height="45dp"
android:onClick="onClickListenerBtnIniciar"
android:text="PLAY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.605" />

<Button
android:id="@+id/btnFinalizar"
android:layout_width="150dp"
android:layout_height="48dp"
android:onClick="onClickListenerBtnFinalizar"
android:text="STOP"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.709" />

<TextView
android:id="@+id/textView"
android:layout_width="258dp"
android:layout_height="34dp"
android:fontFamily="sans-serif-black"
android:text="Reproductor de Música"
android:textColorLink="@color/colorAccent"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />

<ImageView
android:id="@+id/imageView"
android:layout_width="165dp"
android:layout_height="170dp"
android:layout_marginTop="28dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.074
app:srcCompat="@mipmap/logo_ug" />
</LinearLayout >

}
}

public class MainActivity extends AppCompatActivity {


private Context thisConte = this;
private Button btnIniciar;
private Button btnFinalizar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnIniciar = (Button) btnIniciar.findViewById(R.id.btnIniciar);
btnFinalizar = (Button) btnFinalizar.findViewById(R.id.btnFinalizar);

btnIniciar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
onClickListenerBtnIniciar(view);
}
});

btnFinalizar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onClickListenerBtnFinalizar(view);
}
});
}

private void setContentView(int activity_main) {


}

public void onClickListenerBtnIniciar(View view){


Intent i = new Intent(thisConte, ServiceMusic.class,);
thisConte.startService(i);

public void onClickListenerBtnFinalizar(View view) {


Intent i = new Intent(thisConte, ServiceMusic.class,);
thisConte.stopService(i);
}
}

package com.example.servicio;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.content.ContentValues;
import android.content.Context;
import android.media.MediaPlayer;
import android.widget.Button;
import android.widget.Toast;

public class ServiceMusic extends Service {


private Context thisContext =this;
private MediaPlayer mediaPlayer;
private Button btnIniciar;
private Button btnFinalizar;
MediaPlayer vectormp []= new MediaPlayer[2];
int posicion=0;
public ServiceMusic() {

@Override
public void onCreate(){
btnIniciar = (Button) btnIniciar.findViewById(R.id.btnIniciar);
btnFinalizar = (Button) btnFinalizar.findViewById(R.id.btnFinalizar);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId){
vectormp[0] =MediaPlayer.create(thisContext, R.raw.cancion1);
vectormp[1] =MediaPlayer.create(thisContext, R.raw.cancion2);
vectormp[2] =MediaPlayer.create(thisContext, R.raw.cancion3);
if(vectormp[posicion].isPlaying())
{
vectormp[posicion].pause();
Toast.makeText(thisContext,"Pausa", Toast.LENGTH_SHORT).show();
}
else
{
vectormp[posicion].start();
Toast.makeText(thisContext,"Play", Toast.LENGTH_SHORT).show();
}
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
mediaPlayer.stop();
mediaPlayer.release();
}

@Override
public IBinder onBind(Intent intent) {
return null;
}
}

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.servicio" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<service
android:name=".ServiceMusic"
android:enabled="true"
android:exported="true"
/>
</application>
</manifest>

También podría gustarte