Open adetheprince opened 7 years ago
public class VideoFragment extends Fragment {
private ListView listView;
private VideoAdapter adapter;
private static List<VideoLive> mChildArray;
public static VideoFragment getInstance(List<VideoLive> childArray) {
mChildArray = childArray;
VideoFragment v = new VideoFragment();
return v;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_video, container, false);
listView = (ListView) view.findViewById(R.id.listView);
init();
return view;
}
public void init() {
adapter = new VideoAdapter(getContext(), mChildArray);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IMediaPlayer.OnPreparedListener (getContext(), mChildArray.get(position).getChlink(), mChildArray.get(position).getChname());
(( is this correct ?? ?I dont Know what to write here please help)) } }); }
}
You want to play the video when one item was clicked? Maybe you could refer to the code of demo.
yes Sorry I checked the demo but i am totally new to android. Is there easy code i can enter there? Thanks
Could you just show me the jsonstring which is responsed from loginService?
Ok here are all the files that i added hope it will help. Many thanks.
VideoLive.java
package com.ksyun.player.demo.activity;
import java.io.Serializable;
public class VideoLive implements Serializable {
private Integer chid;
private String chname;
private String chlogo;
private String chlink;
private String chenable;
private String chnote;
public Integer getChid() {
return chid;
}
public void setChid(Integer chid) {
this.chid = chid;
}
public String getChname() {
return chname;
}
public void setChname(String chname) {
this.chname = chname;
}
public String getChlogo() {
return chlogo;
}
public void setChlogo(String chlogo) {
this.chlogo = chlogo;
}
public String getChlink() {
return chlink;
}
public void setChlink(String chlink) {
this.chlink = chlink;
}
public String getChenable() {
return chenable;
}
public void setChenable(String chenable) {
this.chenable = chenable;
}
public String getChnote() {
return chnote;
}
public void setChnote(String chnote) {
this.chnote = chnote;
}
}
VideoInfo.java
package com.ksyun.player.demo.activity;
import java.io.Serializable; import java.util.List;
public class VideoInfo implements Serializable {
private String name;
private List
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<VideoLive> getSamples() {
return samples;
}
public void setSamples(List<VideoLive> samples) {
this.samples = samples;
}
}
VideoAdapter
package com.ksyun.player.demo.activity;
import android.content.Context; import android.graphics.Color; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView;
import java.util.List;
public class VideoAdapter extends BaseAdapter {
private Context context;
private List<VideoLive> childArray;
public VideoAdapter(Context context, List<VideoLive> childArray) {
this.context = context;
this.childArray = childArray;
}
@Override
public int getCount() {
return childArray.size();
}
@Override
public Object getItem(int position) {
return childArray.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView view = new TextView(context);
view.setText(childArray.get(position).getChname());
view.setTextColor(Color.BLACK);
return view;
}
}
and last videoservice
package com.ksyun.player.demo.activity;
import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.http.GET;
public interface VideoService {
@GET("chanTest.js")
Call
and chanTest.js looks like this
] },
{ "name": "FRANCE", "samples": [
{
"chid": 134,
"chname": "FR:TCM 1",
"chlogo": "",
"chlink": "http://MyIPAddress:8000/live/Yasirmbl/Test/357.ts",
"chenable": "",
"chnote": ""
},
{
]
Hi there I am trying your code and the demo is good so far, but possible you can help me on how to play the video ? I have modified NetMediaActivity.class to this and its loading fine from my json file saved on the server.
here is my new code which is showing all channels name but on click is missing.
Thanks.
package com.ksyun.player.demo.activity;
import android.graphics.Color; import android.os.Bundle; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Gravity;
import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.TextView;
import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.ksyun.player.demo.R; import com.ksyun.player.demo.model.NetDbAdapter;
import java.io.IOException; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List;
import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import rx.Observable; import rx.functions.Action1;
public class NetMediaActivty extends AppCompatActivity {
}