How to Play Youtube Playlist Intent Videos in Full Screen - android

I am beginner in android and developing an app in which i am using YouTubePlayer API in order to show Youtube Videos of specific Playlist. I'm succeed in doing so. But what I want is that whenever the user selects any video from that playlist; the video should be played in Full Screen. Here is my code:
public class Main4Activity extends AppCompatActivity
{
Toolbar main_toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
main_toolbar=(Toolbar) findViewById(R.id.my_thirdtoolbar);
setSupportActionBar(main_toolbar);
getSupportActionBar().setTitle(R.string.my_tb_title);
getSupportActionBar().setIcon(R.drawable.tblogo);
OnClickButtonListener();
}
public void OnClickButtonListener()
{
Button youtubebtn = (Button) findViewById(R.id.button8);
youtubebtn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
String PLAYLIST_ID = "PLXRActLQ03oY_6AQb-5EMuKFYQA_fDE40";
Intent intent=YouTubeIntents.createOpenPlaylistIntent(Main4Activity.this,PLAYLIST_ID);
startActivity(intent);
}
}
);
}
}

You can use methods from YouTubeIntents. Here are some methods that you can use:
canResolvePlayVideoIntentWithOptions (Context context)
Checks if the YouTube application installed on the user's device supports the fullscreen and finishOnEnd optional parameters when resolving a play video intent.
If this method returns true, then your application can call the createPlayVideoIntentWithOptions(Context context, String videoId, boolean fullscreen, boolean finishOnEnd) method which creates an Intent that, when resolved, will start playing the video specified by videoId, within the YouTube application.
If this method returns false, then your application should call the createPlayVideoIntent(Context context, String videoId) method instead.
Additionally, please also check other implementations and try the suggested solutions in this SO post. Hope it helps!

Related

WeChat InApp payment screen shows up only for first time

I'm trying to implement WeChat InApp payments in our app. But we are struggling to make it work.
I will try to sum it up real quick.
Given user is not logged in, WeChat login screen show up every time.
Given user is logged in, when clicked on pay button for a first time, WeChat order info screen shows up, but when clicked back, and clicked on pay button again (in our app), WeChat screen doesn’t show up.
We did implemented WXPayEntryActivity but neither onCreate, onNewIntent nor onResp are called. And yes, this activity is sending broadcast but neither toast nor log shows up.
I tried call registerApp on application started, I tried it just before creating payment req.
Did anybody come across this issue?
Can WeChat help me directly?
Want to see some code?
This is my payment class
public class WXInAppPayment {
public void startPayment(AppCompatActivity activity, PaymentDataResponse data) {
IWXAPI api = getApi(activity);
if (api.isWXAppInstalled()) {
api.sendReq(getPayRequest(data));
} else {
// Showing toast
}
}
public WXReceiver getReceiver() {
// returning BR for wechat payments
return new WXReceiver();
}
public IntentFilter getIntentFilter() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constants.WE_CHAT_BR_ID);
return intentFilter;
}
private IWXAPI getApi(AppCompatActivity activity) {
final IWXAPI api = WXAPIFactory.createWXAPI(activity, null);
api.registerApp(Constants.WE_CHAT_APP_ID);
return api;
}
private PayReq getPayRequest(PaymentDataResponse data) {
PayReq request = new PayReq();
request.appId = dataFromAPI.appId;
request.partnerId = dataFromAPI.partnerId;
request.prepayId = dataFromAPI.prepayId;
request.packageValue = dataFromAPI.packageValue;
request.nonceStr = dataFromAPI.nonceStr;
request.timeStamp = dataFromAPI.timestimeStampamp;
request.sign = dataFromAPI.sign;
return request;
}
}
And this is WXPayEntryActivity. In manifest:
<activity android:name=".wxapi.WXPayEntryActivity"
android:label="#string/app_name"
android:exported="true"/>
And class:
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private final String TAG = getClass().getSimpleName();
private IWXAPI api;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, Constants.WE_CHAT_APP_ID);
api.handleIntent(getIntent(), this);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent, this);
}
#Override
public void onReq(BaseReq baseReq) {
Log.e(TAG, "onReq: " + baseReq.transaction);
}
#Override
public void onResp(BaseResp baseResp) {
Log.e(TAG, "onResp: " + baseResp.errStr + " " + baseResp.errCode);
Intent intent = new Intent(Constants.WE_CHAT_BR_ID);
intent.putExtra("error_code", baseResp.errCode);
intent.putExtra("error_string", baseResp.errStr);
sendBroadcast(intent);
finish();
}
}
I went through same issue... Your code look fine.
lets cover the scenario:
This is normal ... if user is not logged in.. Wechat App will
redirect to login screen
"Only first time payment passed" happened due to wrong packageName. consider these checks:
You need to use ApplicationId not packageName
WhiteSpace
Debug buildType by default has suffix: .debug to applicatonId
Check AppSign which is MD5 of cert you sign with.. Be careful not to use the default one for debug buildType.
Try to reassign ApplicationId and AppSign it again.(that was our issue 😞) due to hidden WS not visible.
Contact Wechat team support.. they have logs to payment.

Load Video from Firebase Storage to videoView

I want to play a video from Firebase storage with a videoview I'm trying like this:
storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
//Toast.makeText(Chat.this, uri.toString(), Toast.LENGTH_SHORT).show();
MediaController mc = new MediaController(Chat.this);
videoView.setMediaController(mc);
videoView.setVideoURI(uri);
videoView.requestFocus();
//videoView.start();
}
});
But it wont play. The video is empty.
First of all, be certain that the video in Storage is actually in a format that Android devices can play. VideoView cannot play everything - only the types of videos that Android supports.
What you're doing now by passing the uri directly into the VideoView is interpreted as an attempt to stream the video from the given uri. Firebase Storage doesn't support video streaming, so that's won't work. Streaming from a uri requires that the server on the other end be able to stream the given resource.
If want to play a video from Storage, you'll have to download entirety first, saved to a local file, then point the VideoView at the local file for playback.
I think the time is late for the answer, but this answer to those who are looking for it later:
Via RecyclerView View dial Uri from the data Snapshot in adapter
#Override
protected void onStart() {
super.onStart();
final FirebaseRecyclerAdap...///
) {
#Override
protected void popul...////
/////
viewHolder.setVideo(Uri.parse(String.valueOf(videoUri)),model.getVideo());
// Here the position is sent to videoview adapter
final String post_key = getRef( position ).getKey().toString();
final String post_id = String.valueOf(post_key);
viewHolder.setUid(model.getUid());
// Here the position is sent to videoview adapter
viewHolder.setVideo(post_id);
viewHolder.setUserprofile(getApplication(),model.getUserprofile());
}
yourAdpater ....
}
public static class ViewHolder extends RecyclerView.ViewHolder {
View mView;
Videoview post_video ;
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
post_video = (VideoView ) mView.findViewById(R.id.videoView);
}
public void setVideo(final String post_id) {
mDatabase.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
//
Uri uri=Uri.parse(dataSnapshot.child(post_id).child("video").getValue(true).toString());
//You can set up the video display as you like
post_video.setVideoURI(uri);
post_video.requestFocus();
post_video.start();
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
The databases should look like this:
look here.
good luck.
may be possible this by storing videos URLs in Database, then present them in Recyclerview which consists of Webview/Youtube Integration in Single row
I had the same problem and the following solution worked for me:
Add this string to AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET" />

interact with YouTube app on android

I would like to interact with YouTube app on android.
My app is basically a service that is running all the time.
I wanna detect if user was watching YouTube and then lock the phone, when he come back the last watched video should continue playing.
Any suggestions? Where to start?
I am thinking to implement a software touch on play button. Is there any other way to do it?
Here is how you can force a video:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
startActivity(intent);
Obtaining the Android API Key
First we need to get the SHA-1 fingerprint on your machine using java keytool. Execute the below command in cmd/terminal to get the SHA-1 fingerprint.
Go to Google Developer Console and select or create a new project.
On the left sidebar, select APIs under APIs & auth and turn the status ON for YouTube Data API v3.
On the left sidebar, select Credentials and Create new key under Public API acess.
When popup comes asking you to choose platform, select Android Key.
Paste the SHA-1 key and your project’s package name separated by semicolon(;).
Click on create. Now you should see the API KEY on the dashboard.
public class MainActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
private static final int RECOVERY_DIALOG_REQUEST = 1;
// YouTube player view
private YouTubePlayerView youTubeView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
// Initializing video player with developer key
youTubeView.initialize(Config.DEVELOPER_KEY, this);
}
#Override
public void onInitializationFailure(YouTubePlayer.Provider provider,
YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
} else {
String errorMessage = String.format(
getString(R.string.error_player), errorReason.toString());
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
}
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider,
YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
// loadVideo() will auto play video
// Use cueVideo() method, if you don't want to play it automatically
player.loadVideo(Config.YOUTUBE_VIDEO_CODE);
// Hiding player controls
player.setPlayerStyle(PlayerStyle.CHROMELESS);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RECOVERY_DIALOG_REQUEST) {
// Retry initialization if user performed a recovery action
getYouTubePlayerProvider().initialize(Config.DEVELOPER_KEY, this);
}
}
private YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}
}

How to play youtube video using Youtube Data api v3 Android?

Few days back I asked question Youtube API v2 not supported So as per youtube they have deprecated and all application and websites using this v2 api wont work at all. As they told to migrate to v3 there are any good example or documents for android. I have youtube url with video id. I just want to play videos using this api
You can use Video ID to play video...
Use YouTubePlayerView for that...
Let me show you a example which will makes everything clear....
below is a class which contains a YouTubePlayerView..
public class Play_youtube_video extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener
{
YouTubePlayerView video_player;
public static String VIDEO_ID = "";
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// HIDE THE KEYBOARD
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
// TITLE BAR DISABLES AND FULL SCREEN IMPLEMENTATION
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_play_youtube_video);
try
{
System.out.println("youtube----VIDEO_ID---->" + VIDEO_ID);
video_player = (YouTubePlayerView) findViewById(R.id.youtubeplayerview_full_screen);
video_player.initialize(GlobalConstant.YOUTUBE_APIKEY, Play_youtube_video.this);
}
catch(Exception e)
{
e.printStackTrace();
}
catch(OutOfMemoryError e)
{
e.printStackTrace();
}
}
#Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult result)
{
GlobalUtills.showToast("Youtube player not found.", Play_youtube_video.this);
}
#Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored)
{
if( !wasRestored )
{
player.loadVideo(Youtube_VIDEO_ID);
// player.setFullscreen(true);
// player.play();
}
}
public void closeYoutube(View v)
{
Play_youtube_video.this.finish();
}
}
I am answering this question because after some frustration it was not on android api related issue but Gdata youtube api i was using was returning wrong results.
Now its fixed.

Streaming MP4 problem - obvious answer?

I'm a Flash developer by trade, have recently made the jump into Android as the company I work for are moving into apps. I've made a video gallery based on an XML feed, it all works fine until I have to play the movie itself, at which point I get:
Unable to play video. Invalid streaming data.
My gallery items fire up another activity with the .mp4 link as an extra:
public class Video_play extends Activity implements View.OnClickListener {
String vLink;
Uri vid;
VideoView vv;
MediaPlayer mp;
SurfaceHolder holder;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//Hide app title
Bundle extras = getIntent().getExtras();
if (extras != null) {
vLink = extras.getString("video");
vid = Uri.parse(vLink);
}
setContentView(R.layout.vidplay_layout);
vv = (VideoView)findViewById(R.id.vid_fscreen);
Log.i("Video link is: ",vid+"");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(vv);
vv.setMediaController(mediaController);
vv.setVideoURI(vid);
vv.start();
}
public void onClick(View v) {
}
}
I've been looking all afternoon and I can't find any straightforward advice on what I'm doing wrong. Any help would be absolutely life-saving, thanks in advance.
What version of Android are you testing it on? HTTP progressive streaming for MP4 video was not fully supported until Android 2.2.
For streaming playback on earlier Android versions you can usually work around this by using post-encoding software like MP4Box to add "hint tracks" to the file:
MP4Box -hint <filename>
http://www.videohelp.com/tools/mp4box

Categories

Resources