I am creating video playing app from Youtube. I have extracted Video Data using gdata API and got 3gp url for format 1,6. This i got extracted from Media:Group --> Media:content element. My Device Info Android 4.0.3 and Model Micromax P350.
These video is working in VLC Player but not in VideoView enter code here`w in my app. Here is my code:
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_height="fill_parent"
androidaddingLeft="2px"
androidaddingRight="2px"
xmlns:android="schemas.android.com/apk/res/android"
androidaddi`enter code here`ngTop="2px"
androidaddingBottom="2px"
android:layout_width="fill_parent"
androidrientation="vertical">
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView" />
</LinearLayout>
package com.example.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView)findViewById(R.id.VideoView);
//MediaController mediaController = new MediaController(this);
// mediaController.setAnchorView(videoView);
//videoView.setMediaController(mediaController);
videoView.setVideoPath("v1.cache8.c.youtube.com/CiILENy73wIaGQneb1Sj_PGnoRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video_3gp");
videoView.start();
}
}
Related
I'm looking to make my website button turn into a link. and the text within textview that says "website" a link as well. Any help?
Code:
<?xml version="1.0" encoding="utf-8"?>
<Button
android:id="@+id/widget34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/website"
android:layout_x="0dp"
android:layout_y="36dp" />
</LinearLayout>
Code:
package com.example.hi;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Hi extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Visit my website!");
setContentView(tv);
}
}
Hey Guys
I am developing a chat client that would connect to gtalk server.. I am just doing this to learn Android programming. I know that I have to use XMPP to connect to google talk server. I am having issues when attempting to do Connection.connect(). I get a whole bunch of errors from FatalException, Networkmainthreadexception and so on...
I ran the same code in a seperate java project and the whole thing ran without any problems.. I have enabled internet in the manifest file.
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
Here is my main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="(removed due to # of post restriction...)://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:text="@string/user_name"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:text=""
android:id="@+id/txtUname"
android:layout_width="fill_parent"
android:hint="@string/userName_hint"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow>
<TextView
android:text="@string/password"
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText
android:text=""
android:id="@+id/txtPwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:password="true">
</EditText>
</TableRow>
<TableRow>
<Button
android:text="Cancel"
android:id="@+id/btnCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
<Button
android:text="Login"
android:id="@+id/btnLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
</TableRow>
</TableLayout>
MyGtalkActivity.java
Code:
package com.tanmay.gtalk;
import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
public class MyGTalkActivity extends Activity {
EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtUserName = (EditText) this.findViewById(R.id.txtUname);
txtPassword = (EditText) this.findViewById(R.id.txtPwd);
btnLogin = (Button) this.findViewById(R.id.btnLogin);
btnLogin = (Button) this.findViewById(R.id.btnLogin);
//String userName = (String) getText(R.id.txtUname);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//Log.i(tag, msg)
/*ConnectionConfiguration connConfig =
new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(connConfig);*/
ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection xmpp = new XMPPConnection(cc);
try {
System.out.println("testtt");
xmpp.connect();
xmpp.login("[email protected]", "***");
Presence presence = new Presence(Presence.Type.available);
xmpp.sendPacket(presence);
System.out.println("testt123");
//Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
} catch (XMPPException e) {
// TODO Auto-generated catch block
Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + xmpp.getHost());
Log.e("XMPPClient", e.toString());
//e.printStackTrace();
}
//dismiss();
}
});
}
}
I have attached the errors that i get on my console...Any sugestions ?
thanks
Tanmay
Hey
You are getting the NetworkOnMainThread exception which i'd guess means that Android doesn't take too well to you trying to make a network connection on the applications main thread.
You should try to make a new thread and put the XMPP connection code in that thread and it should get rid of the errors.
I hope you are aware of multithreading and threads. If not, this is a good time to read and learn about it
EDIT: The reason it works well in your Java program is because there is no such restriction in a regular Java program. Android is very different from that.
Thanks for the reply.. I will look up multi-threading...
Hi,
I started following the 'Building your first app' on developer.android.com,
I like to do it but now after following the instructions fully it is crashing when you click the button.
I used as build platform Android 4.1, but that should not matter...
I included the codes down here, I hope anyone can help.
MyFirstActivity.java:
Code:
package com.example.lesson.one;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MyFirstActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// It crashes here, because here is the part where you push the button.
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
DisplayMessageActivity.java:
Code:
package com.example.lesson.one;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MyFirstActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
}
AndroidManifest.xml:
Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MJV.lesson.one"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyFirstActivity"
android:label="@string/title_activity_my_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.myapp.DisplayMessageActivity" />
</application>
</manifest>
Strings.xml:
Code:
<resources>
<string name="app_name">Lesson ONE</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_my_first">MyFirstActivity</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
</resources>
Main.xml:
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
I hope anyone can help me... Because Eclipse isn't giving any errors...
Edit 1: I tried it again, now without any things in the new activity. ( I mean without any code it must do ).
It still crashes, so its somewhere where it will start the new activity.
Edit 2: I ran a logcat, but I know now it cant find DisplayMessageActivity in androidmanifest.xml... Though its already added.
Edit 3: I found my problem, it was in androidmanifest.xml. I stated DisplayMessageActivity wrong! I read too quickly and skipped that part...
Hi Everyone.. I'm a beginner in Android programming, I have a problem in string reference. Please help.. Thanks
Here's my code..
activity_main.xml
Code:
<LinearLayout xmlns:android="h t t p : / / schemas . android . com / apk / res / android"
xmlns:tools="h t t p : / / schemas . android . com / tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tvDisplay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/score"
android:textSize="45sp"
android:layout_gravity="center"
android:gravity="center" />
<Button
android:id="@+id/bAdd"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/add"
android:layout_gravity="center"
android:textSize="20sp" />
<Button
android:id="@+id/bSub"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/sub"
android:layout_gravity="center"
android:textSize="20sp" />
</LinearLayout>
string.xml
Code:
display.setText("Your total is " + counter);<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="action_settings">Settings</string>
<string name="score">Your Score is 0</string>
<string name="add">Add one</string>
<string name="sub">Subtract one</string>
</resources>
MainActivity.java
Code:
package com.ben.myfirstapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int counter;
Button add, sub;
TextView display;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button)findViewById(R.id.bAdd);
sub = (Button)findViewById(R.id.bSub);
display = (TextView)findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
counter--;
display.setText("Your total is " + counter);
}
});
}
[user=439709]@override[/user]
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;
}
}
Here's a screenshot of the Graphic Layout..
Issue is in your string.xml file... The first line remove
>>> display.setText("...);<<< and it should work
Video is visual multimedia source that combines a sequence of images to form a moving picture. The video transmits a signal to a screen and processes the order in which the screen captures should be shown.
Videos usually have audio components that correspond with the pictures being shown on the screen.
Video was first developed for “Mechanical Television” systems which were quickly replaced by cathode ray tube (CRT) and eventually replaced by flat panel displays of several types.
Huawei Video Kit brings the wonderful experience to playback the high quality videos streaming from a third party cloud platform.
Huawei Video Kit supports the streaming media in 3GP,MP4 or TS formats and comply with HTTP/HTTPS, HLS or DASH.
Huawei Video Kit will also be supporting the video hosting and editing feature in coming versions.
Features
Video Kit provides smooth playback.
It provides secure and stable solution.
It leverages the anti-leeching experience so that bandwidth is not drained out.
It allows wide ranging playback controls.
Supports playback authentication.
Development Overview
Prerequisite
Must have a Huawei Developer Account
Must have Android Studio 3.0 or later
Must have a Huawei phone with HMS Core 5.0.0.300 or later
EMUI 3.0 or later
Software Requirements
Java SDK 1.7 or later
Android 5.0 or later
Preparation
Create an app or project in the Huawei AppGallery Connect.
Provide the SHA Key and App Package name of the project in App Information Section and enable the required API.
Create an Android project.
Note: Video Kit SDK can be directly called by devices, without connecting to AppGallery Connect and hence it is not mandatory to download and integrate the agconnect-services.json.
Integration
Add below to build.gradle (project)file, under buildscript/repositories and allprojects/repositories.
Code:
<p style="line-height: normal;">Maven {url 'http://developer.huawei.com/repo/'}</p>
Add below to build.gradle (app) file, under dependencies.
Code:
<p style="line-height: normal;">implementation "com.huawei.hms:videokit-player:1.0.1.300" </p>
Adding permissions
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE" />
Development Process
A small trip application has been created to demonstrate the capabilities to Huawei Video Kit.
It lists all the amusement places to visit around with the use of GridView RecyclerView and card view.
To achieve it below classes are created.
Initializing WisePlayer
We have to implement a class that inherits Application and the onCreate() method has to call the initialization API WisePlayerFactory.initFactory().
Code:
public class VideoKitPlayApplication extends Application {
private static final String TAG = VideoKitPlayApplication.class.getSimpleName();
private static WisePlayerFactory wisePlayerFactory = null;
@Override
public void onCreate() {
super.onCreate();
initPlayer();
}
private void initPlayer() {
// DeviceId test is used in the demo.
WisePlayerFactoryOptions factoryOptions = new WisePlayerFactoryOptions.Builder().setDeviceId("xxx").build();
WisePlayerFactory.initFactory(this, factoryOptions, initFactoryCallback);
}
/**
* Player initialization callback
*/
private static InitFactoryCallback initFactoryCallback = new InitFactoryCallback() {
@Override
public void onSuccess(WisePlayerFactory wisePlayerFactory) {
LogUtil.i(TAG, "init player factory success");
setWisePlayerFactory(wisePlayerFactory);
}
@Override
public void onFailure(int errorCode, String reason) {
LogUtil.w(TAG, "init player factory failed :" + reason + ", errorCode is " + errorCode);
}
};
/**
* Get WisePlayer Factory
*
* @return WisePlayer Factory
*/
public static WisePlayerFactory getWisePlayerFactory() {
return wisePlayerFactory;
}
private static void setWisePlayerFactory(WisePlayerFactory wisePlayerFactory) {
VideoKitPlayApplication.wisePlayerFactory = wisePlayerFactory;
}
}
Creating instance of wise player
Code:
wisePlayer = VideoKitPlayApplication.getWisePlayerFactory().createWisePlayer();
WisePlayer layout
Code:
private void initView(View view) {
if (view != null) {
surfaceView = (SurfaceView) view.findViewById(R.id.surface_view);
textureView = (TextureView) view.findViewById(R.id.texture_view);
if (PlayControlUtil.isSurfaceView()) {
//SurfaceView display interface
SurfaceHolder surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(thois);
textureView.setVisibility(View.GONE);
surfaceView.setVisibility(View.VISIBLE);
} else {
//TextureView display interface
textureView.setSurfaceTextureListener(this);
textureView.setVisibility(View.VISIBLE);
surfaceView.setVisibility(View.GONE);
}
}
Register WisePlayer listeners
Code:
private void setPlayListener() {
if (wisePlayer != null) {
wisePlayer.setErrorListener(onWisePlayerListener);
wisePlayer.setEventListener(onWisePlayerListener);
wisePlayer.setResolutionUpdatedListener(onWisePlayerListener);
wisePlayer.setReadyListener(onWisePlayerListener);
wisePlayer.setLoadingListener(onWisePlayerListener);
wisePlayer.setPlayEndListener(onWisePlayerListener);
wisePlayer.setSeekEndListener(onWisePlayerListener);
}
}
Set playback parameters
Code:
player.setVideoType(PlayMode.PLAY_MODE_NORMAL);
player.setBookmark(10000);
player.setCycleMode(CycleMode.MODE_CYCLE);
Set URL for video
Code:
wisePlayer.setPlayUrl(new String[] {currentPlayData.getUrl()});
Set a view to display the video.
Code:
// SurfaceView listener callback
@Override
public void surfaceCreated(SurfaceHolder holder) {
wisePlayer.setView(surfaceView);
}
// TextureView listener callback
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
wisePlayer.setView(textureView);
// Call the resume API to bring WisePlayer to the foreground.
wisePlayer.resume(ResumeType.KEEP);
}
Prepare for the playback and start requesting data.
Code:
wisePlayer.ready();
Start the playback After success response
Code:
@Override
public void onReady(WisePlayer wisePlayer) {
player.start();
}
activity main.xml
Create a view for Recycler View.
Code:
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/player_recycler_view"
android:background="@drawable/images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp" />
</RelativeLayout>
select_play_view
Create card view for displaying the trip locations.
Code:
<?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="wrap_content"
android:orientation="vertical"
android:tag="cards main container">
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_margin="5dp"
card_view:cardBackgroundColor="@color/cardcolour"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<ImageView
android:id="@+id/videoIcon"
android:tag="image_tag"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="@drawable/1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="2"
android:orientation="vertical"
>
<TextView
android:id="@+id/play_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text=""
android:textColor="@color/colorTitle"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="@+id/briefStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp"
android:textColor="@color/green"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/play_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="@color/select_play_text_color"
android:textSize="20sp"
android:visibility="gone"/>
<TextView
android:id="@+id/play_url"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="2"
android:paddingTop="5dip"
android:singleLine="false"
android:textColor="@color/select_play_text_color"
android:textSize="14sp"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Data Adapter to hold the data for Recycler View
Code:
package com.huawei.video.kit.demo.adapter;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.huawei.video.kit.demo.R;
import com.huawei.video.kit.demo.contract.OnItemClickListener;
import com.huawei.video.kit.demo.entity.PlayEntity;
import com.huawei.video.kit.demo.utils.LogUtil;
import com.huawei.video.kit.demo.utils.StringUtil;
import com.squareup.picasso.Picasso;
/**
* Play recyclerView adapter
*/
public class SelectPlayDataAdapter extends RecyclerView.Adapter<SelectPlayDataAdapter.PlayViewHolder> {
private static final String TAG = "SelectPlayDataAdapter";
// Data sources list
private List<PlayEntity> playList;
// Context
private Context context;
// Click item listener
private OnItemClickListener onItemClickListener;
/**
* Constructor
*
* @param context Context
* @param onItemClickListener Listener
*/
public SelectPlayDataAdapter(Context context, OnItemClickListener onItemClickListener) {
this.context = context;
playList = new ArrayList<>();
this.onItemClickListener = onItemClickListener;
}
/**
* Set list data
*
* @param playList Play data
*/
public void setSelectPlayList(List<PlayEntity> playList) {
if (this.playList.size() > 0) {
this.playList.clear();
}
this.playList.addAll(playList);
notifyDataSetChanged();
}
@NonNull
@Override
public PlayViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.select_play_item, parent, false);
return new PlayViewHolder(view);
}
@Override
public void onBindViewHolder(PlayViewHolder holder, final int position) {
if (playList.size() > position && holder != null) {
PlayEntity playEntity = playList.get(position);
if (playEntity == null) {
LogUtil.i(TAG, "current item data is empty.");
return;
}
StringUtil.setTextValue(holder.playName, playEntity.getName());
//StringUtil.setTextValue(holder.releasedYear, playEntity.getYear());
StringUtil.setTextValue(holder.briefStory, playEntity.getStory());
StringUtil.setTextValue(holder.playUrl, playEntity.getUrl());
StringUtil.setTextValue(holder.playType, String.valueOf(playEntity.getUrlType()));
holder.itemView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onItemClickListener.onItemClick(position);
}
});
Picasso.with(context).load(playEntity.getIcon()).into(holder.videoIcon);
}
}
@Override
public int getItemCount() {
return playList.size();
}
/**
* Show view holder
*/
static class PlayViewHolder extends RecyclerView.ViewHolder {
// The video name
private TextView playName;
private TextView briefStory;
// The video type
private TextView playType;
// The video url
private TextView playUrl;
private ImageView videoIcon
/**
* Constructor
*
* @param itemView Item view
*/
public PlayViewHolder(View itemView) {
super(itemView);
if (itemView != null) {
playName = itemView.findViewById(R.id.play_name);
briefStory = itemView.findViewById(R.id.briefStory);
playType = itemView.findViewById(R.id.play_type);
playUrl = itemView.findViewById(R.id.play_url);
videoIcon = itemView.findViewById(R.id.videoIcon);
}
}
}
}
HomePageView
This associated with the view of recycler view.
Code:
package com.huawei.video.kit.demo.view;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.huawei.video.kit.demo.R;
import com.huawei.video.kit.demo.adapter.SelectPlayDataAdapter;
import com.huawei.video.kit.demo.contract.OnHomePageListener;
import com.huawei.video.kit.demo.entity.PlayEntity;
import com.huawei.video.kit.demo.utils.DialogUtil;
/**
* Home page view
*/
public class HomePageView {
int numberOfColumns = 2;
// Home page parent view
private View contentView;
// Context
private Context context;
// Play recyclerView
private RecyclerView playRecyclerView;
// Input play url
private EditText addressEt;
// Play button
private Button playBt;
// Play adapter
private SelectPlayDataAdapter selectPlayDataAdapter;
// Listener
private OnHomePageListener onHomePageListener;
/**
* Constructor
*
* @param context Context
* @param onHomePageListener Listener
*/
public HomePageView(Context context, OnHomePageListener onHomePageListener) {
this.context = context;
this.onHomePageListener = onHomePageListener;
initView();
}
/**
* Get parent view
*
* @return Parent view
*/
public View getContentView() {
return contentView;
}
/**
* Init view
*/
private void initView() {
contentView = LayoutInflater.from(context).inflate(R.layout.activity_main, null);
playRecyclerView = (RecyclerView) contentView.findViewById(R.id.player_recycler_view);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context.getApplicationContext(),numberOfColumns);
playRecyclerView.setLayoutManager(gridLayoutManager);
playLoading = (ProgressBar) contentView.findViewById(R.id.play_loading);
addressEt = (EditText) contentView.findViewById(R.id.input_path_ed);
playBt = (Button) contentView.findViewById(R.id.main_play_btn);
playBt.setOnClickListener(onHomePageListener);
selectPlayDataAdapter = new SelectPlayDataAdapter(context, onHomePageListener);
// playRecyclerView.setLayoutManager(new LinearLayoutManager(context));
playRecyclerView.setAdapter(selectPlayDataAdapter);
playRecyclerView.setVisibility(View.GONE);
playLoading.setVisibility(View.VISIBLE);
}
/**
* Set the current data list
*
* @param playList Data list
*/
public void updateRecyclerView(List<PlayEntity> playList) {
selectPlayDataAdapter.setSelectPlayList(playList);
playLoading.setVisibility(View.GONE);
playRecyclerView.setVisibility(View.VISIBLE);
}
/**
* Get input text
*
* @return Text value
*/
public String getInputUrl() {
if (addressEt.getText() == null) {
return "";
} else {
return addressEt.getText().toString();
}
}
}
Results
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Conclusion
We learnt a simple application which explains the power video kit apis and showcase how easy it to have the videos running in out applications.
References
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/introduction-0000001050439577-V5