Professional Documents
Culture Documents
NewProductsFragment.java
package com.example.softcomfort.ui.newProducts;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import com.example.softcomfort.R;
import java.util.Objects;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_new_products,
container, false);
VideoView videoView_luxury =
root.findViewById(R.id.videoView_luxury);
String videoLuxury = "android.resource://" +
getActivity().getPackageName() + "/" + R.raw.video_furniture_luxury;
Uri uriLuxury = Uri.parse(videoLuxury);
videoView_luxury.setVideoURI(uriLuxury);
MediaController mediaController_luxury = new
MediaController(getActivity());
videoView_luxury.setMediaController(mediaController_luxury);
mediaController_luxury.setAnchorView(videoView_luxury);
VideoView videoView_vintage =
root.findViewById(R.id.videoView_vintage);
String videoVintage = "android.resource://" +
getActivity().getPackageName() + "/" + R.raw.video_furniture_vintage;
Uri uriVintage = Uri.parse(videoVintage);
videoView_vintage.setVideoURI(uriVintage);
MediaController mediaController_vintage = new
MediaController(getActivity());
videoView_vintage.setMediaController(mediaController_vintage);
mediaController_vintage.setAnchorView(videoView_vintage);
return root;
}
}
Fragment_new_products.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="@font/catamaran_bold"
android:text="Pronto"
android:textColor="@color/brown"
android:textSize="24sp"
2
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5" >
<VideoView
android:id="@+id/videoView_luxury"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Linea de Productos Luxury"
android:textColor="@color/brown"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/frameLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="Mas Productos Vintage"
android:textColor="@color/brown"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/frameLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
2
app:layout_constraintTop_toBottomOf="@+id/frameLayout" />
<FrameLayout
android:id="@+id/frameLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6">
<VideoView
android:id="@+id/videoView_vintage"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_gravity="center" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
2
Vistas del emulador
2
CUESTIONARIO
1. ¿Cómo se añade el manejo de audio y video en una aplicación Android?
Luego de la incorporación del audio o video en una aplicación Android, el
manejo es recomendable hacerlo mediante botones incluidos en el Layout que
incluya los botones principales como son play, pause y stop, aquí un ejemplo de
dicho código:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
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"
tools:context="com.academiaandroid.demomultimedia.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
>
<Button
android:text="PLAY"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonPlay"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/buttonPause"
android:layout_toStartOf="@+id/buttonPause"
android:layout_marginBottom="20dp" />
<Button
android:text="PAUSE"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonPause"
android:layout_alignBaseline="@+id/buttonPlay"
android:layout_alignBottom="@+id/buttonPlay"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
<Button
android:text="STOP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonStop"
android:layout_alignBaseline="@+id/buttonPause"
android:layout_alignBottom="@+id/buttonPause"
android:layout_toRightOf="@+id/buttonPause"
2
android:layout_toEndOf="@+id/buttonPause"
/>
</LinearLayout>
</RelativeLayout>