I developed an application that receives a YOUTUBE URL from other users and plays it in the youtube player. But I want that URL to play in youtube Webview which I have in my Application. I don't have an extensive background in android and Java. This is my third time experimenting with android. So, please help me so I can make some changes in the Onclickmethod of the listview.
Here is the code that I have for playing in the youtube application or either it will ask to choose between youtube and Google chrome.
scanListView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TextView textView = findViewById(R.id.textView);
String text = ((TextView) view).getText().toString();
// textView.setText(text);
String launchUrl = url.concat(getUrlMethod(text,"|"));
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(launchUrl)); //*************************************************************
startActivity(browserIntent);
}
}
);
Related
I am newbie in Android Development and i am developing a android app using recycler view and card view.I created two column using grid layout with 10 rows 20 images Now i want to set a click Listener on every image which starts a new activity that should play a giff animation or video link with that specific image.
public AlphabetRecyclerViewItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Get LayoutInflater object.
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
// Inflate the RecyclerView item layout xml
View alphabetItemView = layoutInflater.inflate(R.layout.activity_card_view_item,parent,false);
final TextView alphabetTitleView = (TextView)alphabetItemView.findViewById(R.id.card_view_image_title);
// Get alphabet image view object.
final ImageView alphabetImageView = (ImageView)alphabetItemView.findViewById(R.id.card_view_image);
alphabetImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Get Alphabet title Text
String alphabetTitle = alphabetTitleView.getText().toString();
// Create a snackbar and show it.
Snackbar snackbar = Snackbar.make(alphabetImageView,"You Clicked" + alphabetTitle + "image",Snackbar.LENGTH_LONG);
snackbar.show();
}
});
// Create and return our custom Alphabet Recycler View Item Holder object.
AlphabetRecyclerViewItemHolder ret =new AlphabetRecyclerViewItemHolder(alphabetItemView);
return ret;
}
I want to play different videos on every image user click.
Add your all images and video in arraylist and set arraylist in recycler view
after setting the adapter use the recyclerview item click and pass the video link from that position to next screen which you want to play in your video player.
How can i make a text clickable in Expandable list-view in Android studio. For example, when i click a text, it should open a webiste in my phone default browser. As you can see in the picture, under Afghanistan, there is Hope Academy Rwanda and website next to it. I want this webiste be clickable over Hope Academy Rwanda in the background. So when I click Hope Academy Rwanda it can take me to google.com[screenshot of expandable list view]
Here is my code;
List<String> afghanistan = new ArrayList<>();
afghanistan.add("Hope Academy Rwanda(www.google.com)");
For ListView you can set the item Clickable by as:
[yourlistview].setOnItemClickListener(new OnItemClickListener(){
#Override
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Here will be your Intent to open the link.
}
});
And then under that you need set Intent to open a particular link:
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Can I ask some help. we have smart android T.V box and already set up. we have 20 T.V channels set up. Now we want to create an android application that can select channel and display it to the screen just like the other cable provider that they have menu or list of their channels and you can select each of them to view on screen.The android app is installed in our smart android T.V box.
I have this simple running code but the problem is that I cannot show it again the list of my channels in order to select other channel I need to press the back button in order to show the list (discouraging I use listview). how can I achieve just like the same other cable provider that they can show the menu of channels on the left side and only will show if they press the menu.
this is what I have so far.
MyActivity.class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
String[] values = new String[] { "Nickelodeon", "Animal Planet", "CNN",
"MTV", "History Channel", "Discovery Channel", "National Geographic Wild", "MovieMAX HD",
"Science Channel", "TLC" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.videolist,R.id.label,values);
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String item = (String) getListAdapter().getItem(position);
Intent intent = new Intent(this, DisplayVid.class);
intent.putExtra("channelextra", item);
startActivity(intent);
}
Showvideo.class
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url = "url chanell here"; // static for my demo purpose only
video = (VideoView) findViewById(R.id.myVideo);
video.setVideoURI(Uri.parse(url));
mediacontroller = new MediaController(this);
mediacontroller.setMediaPlayer(video);
video.setMediaController(mediacontroller);
video.requestFocus();
video.start();
Bundle extras = getIntent().getExtras();
String item = extras.getString("channelextra");
}
Thank you in advance.
I am fetching the youtube id from my server and i make as youtube embed url,after that i am showing that youtube url in listview,while click the listitem the youtube video has to be play in webview,that is my requirement,i tried all the ways its not working for me,its displaying the blank page
like this i am fetching from my server and make as youtube url
app1.setUrlWiki("http://www.youtube.com/embed/"+json.getString("youtube_url")+"?fs=0");
this is my mainactivity.java
lv2 =(ListView)findViewById(R.id.listV_main);
lv2.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv2.getItemAtPosition(position);
Application1 obj_itemDetails = (Application1)o;
Intent intent1=new Intent(PoojaVideos.this,WebViewActivity.class);
//Log.d("test","strContactList: "+strContactList);
//intent1.putExtra("firstKeyName", Uri.parse(((Application1) o).getUrlWiki()));
String link = Uri.parse(((Application1) o).getUrlWiki()).toString();
intent1.putExtra("firstKeyName", link);
startActivity(intent1);
}
});
from there i am sending the url to webview activity according to the click
webviewactivity.java
audio alone coming ,but video is not showing
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
//wv = (WebView) findViewById(R.id.webView);
mContentView = (FrameLayout) findViewById(R.id.main_content);
wv = (WebView) findViewById(R.id.webView);
mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
wv.setWebChromeClient(new WebChromeClient() {
});
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = getHTML();
System.out.println(".................."+html);
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
public String getHTML() {
Intent intent1= getIntent(); // gets the previously created intent
String firstKeyName1 = intent1.getStringExtra("firstKeyName");
Toast.makeText(this, firstKeyName1, 1000).show();
System.out.println("kkkkk."+firstKeyName1);
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src="firstKeyName1" frameborder=\"0\">\n"
+ "</iframe>\n";
return html;
}
webview.xml
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
while click the play button,the audio is running,but the video is not showing,it showing black screen.**
**According to the answer i changed my code,now its working fine;i checked in device its working fine but in emulator audio only coming.so guys check in device**
You have to set the url in the html string in this way:
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src='"+firstKeyName1 +"' frameborder=\"0\">\n"
+ "</iframe>\n";
Now you can easily see the youtube video in that screen.
As per doc
In order to support inline HTML5 video in your application, you need
to have hardware acceleration turned on, and set a WebChromeClient.
For full screen support, implementations of onShowCustomView(View,
WebChromeClient.CustomViewCallback) and onHideCustomView() are
required, getVideoLoadingProgressView() is optional.
put android:hardwareAccelerated="true" in your AndroidManifest.
I'm quite new to this, I have checked for an answer at the forums here but I didn't find any answer that can really help me out. I'm trying to play a video from the res/raw folder. I have set up this code so far:
MediaPlayer mp;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoview);
ListView l1 = (ListView) findViewById(R.id.listview);
l1.setAdapter(new EfficientAdapter(this));
l1.setOnItemClickListener(new OnItemClickListener() {
//Starts up a new activity, based on what listitem you press.
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent intent = new Intent(VideoButtonActivity.this, com.example.norskattrack.VideoActivity.class);
if(position==0){
System.out.println("Item 0");
intent.putExtra("video", 1);
startActivity(intent);
}
if(position==1){
System.out.println("Item 1");
intent.putExtra("video", 2);
startActivity(intent);
}
}
});
}
Uri video = Uri.parse("android.resource://com.package.app/raw/videoname");
That should let you play the video from the raw folder !
have a look at :
How to play videos in android from assets folder or raw folder?
Play Video From Raw Folder
Trying to play video from raw folder (VideoView)
All have excellent answers !