hi guys welcome back to the large
studios we're going to be continuing
from where we stopped in the earlier
tutorial where we took about Android
uploading media file to server using
retrofits we actually talked about the
image upload this time we're going to be
looking at how to upload a video file to
the server the server environment right
the screen you seen and the cPanel and I
have the upload image the PHP file that
actually assisting us in getting these
are uploaded to the server let's get
quickly taking deep into our days our
PHP structure is it takes the target
directory which is the uploads folder
and it's also the file name trying to
gather Farnham with the base name and
you asked the response from the re so
it's good to check if the image file is
actually an image or a fake one we
actually using an image right but they
could work for different our upload our
media types public image videos PDF and
so on so we're going to be going deeper
into an hour to get at the video file
uploaded to the server from an Android
application at the back to undress to do
I have the layout code of video layouts
we've are the image layouts we have the
fidelia's writing which importantly from
the main activity gets us down here so
that's just our cook however this
particular layout and looking at the
preview you get to see this larger
square like shape which serve as the
video view we're actually using the
video of you out of the box with no
using any library without site within
any third-party
functionalities just out of the box one
hundred and two buttons on underneath
the Fox day is to pick an image where
the second is to upload the video to the
server to pick a video and upload the
video to the server there's two buttons
will be interacting with the video view
let's get to look our video activity in
previous story I was talking about how
we're gonna grant permissions run some
permissions basically for Android API 20
21 and above I think marshmallow so 23
on a ball from out into one should be
lollipop so you need to grant runtime
permission 400 versions of that and if
you're using lower version you just
declared the permissions rather than a
manifest so actually cover that in
previous tutorial will be illustrative
how to get the video and upload that to
the server we have the video activity
extends up compacted activity where you
have the views will be talking about
different fields here the importance and
the which is the important to select a
video and the bottom to upload a video
we have a progress bar we have the video
view I right there declared and you have
the URL to out the video and the path of
this URL will be stored and the string
are variable over here so let's continue
now to get this done the current
playback position now that's going to be
in milliseconds I've gotten as an
integer
while the instance of the state bounded
at the play time there's a playback time
you also save as a string static our
variable initialize the Bottineau vm and
also the upload video does the pic video
and upload video the button which is
going to be the peak video sets an
onclicklistener to that are where you
going to provide on click method now
what you going to do you call the intent
which you attach the action gets content
and you need to specify the type which
is going to baby mime type which is
video you're pointing at any video far
be it MPEG be temple to be and before
order and also some other video formats
so it's actually going to be directed to
that and you start an activity for
results passing the intent of the video
with the integer which is like an ID
fire of these requests so you have that
set up
to start an activity after you might
have selected a video that's what that's
gonna do and the upload video also set
on a click listener to that where you go
to be uploading are the content down to
the server using this method upload file
we get to talk about what that file is
going to be doing in h-e-b so let's move
on we have the video of you which is
being initialized and they buffering the
buffering text view so you could also
listen to buffering up there it's
loading or some other Jesus stop that
could actually get the user in tune with
what is actually happening at a point of
the video the other service the state we
could save the playback States so it's
actually going to consider from there
when the rotation of the device to
landscape so up that as well
you need to setup the media controller
which is the widget that attached to the
video view the other media controller
class here you need to call an object
from these by instantiating this and set
the media player to the view which is
the video view and set the media
controller also to the controller so it
does need to be controller which is
actually going to be for fast-forward
pause stop and basically fast-forward
pause and stop and play so you have that
in tune with the controller who did the
dialogue here which is actually going to
get a piece short temporarily when you
are picking the video and display in
deeds to the video view let's move on we
have the unpause when you when you are
doing activities right not on focus or
public's on the background you need to
pause the video so that the video just
don't continue that's just a very good
way to
under-22 very good user experience
probably you have a call at a point in
time when you're listening to the video
you need to pause the video the volume
of the video and even a video and
charlie
so you continue from where you stopped
when you're returning back to the
activity and I'll stop you need to
release the player that that means they
are the activity has been closed and you
need to
we need the player for all that Colin
activity that needs the service of the
media player so you need to call the
release player about it you get to look
at the content of the metric right there
and on the save instance stage we are
trying to gather current position which
is the playback position and
milliseconds to the instant step bundle
I call the updates put in at the
playback time and they get composition
based on the video of you that's when
you're trying to change orientation from
portrait to landscape you need to get a
consistent flow of the video now the
initialize player where do you need to
trigger this method let's look at this
this battle right there we'll get to
look at when you need to get so get back
to the method on activity for result we
get to pass the request for the results
code and the in send data you get all
the super onactivityresult pass those
three parameters and when the resort
code is okay and also the request code
is the integer does the identifier of a
video you get to pass this data further
and you test if the data which is the
intent is not the customer does a very
good standard you pass this you get the
data from the intent you pass that to
the video you are a duck say you are you
getting now that's just not enough it
could be good for explaining to add a
video view since you just need a a URL
to display to the view which prefers
writing in the initialize player but you
need to get the part the real part
further we are trying to upload that
particular flower or that particular non
in non media type to the server so
that's why we call the get part method
on the URL we got to look at that later
on but before we do that let's look at
the initialize player that's good
electronic display the video - the video
view the initial act initialized a and
listen to what the URL which would be
who passed that after once you have the
activity for results and you have the
buffer in text view to set a possibility
at a point in time we test for the URI
if is not supposed to know if it's not
just set the video you are a based on
the video view
now you're going to be listening for
some stop the unprepared events and now
you go to settle you video you are a
let's get to look cool let's move on
buh-bye you said that to the video view
now you're gonna listen for unprepared
events that runs after the media is
prepared now set on prepared listener to
the video of you where you need to share
the media player on prepare listener
bye-bye you need to provide a method
unprepared so what's gonna happen that's
when you get set the possibility of the
buffering to invisible you restore the
safe instance position if available
that's the sick upper which is are the
they are they Denali the the player
controller now else you skip to show the
first frame of the video let's get us
started and stopped playing the video
calling the video view starts mattered
so it's actually going to start playing
the video immediately it gets out the
full capacity of the URL now that's a
listener for all completion events that
runs after the media's finished playing
that's when the media finished playing
completely reset on completion listener
to the Vedic view I also Institute the
media player on completion listener
which you need to override a method
called on completion passing the media
players as parameter objects and you
could actually post a message probably
the playback is completed or to
something and now what's going to happen
to the the sick which is DRD you return
the video position to the start that
it's being completed so it's actually
going to start up again so that's just
what that's going to do now when you're
releasing the player you need to stop
the playback that's when your are closed
in the application when the application
closes completely when it stops which
the activity in question stops is good
to actually call the stop playback on
the view
of you we have that settled out now
after that we're going to get to look at
the path are you going to get the
complete part of the ula and upload to
the server
now I'm going to get a complete part
based on the URI got him does not just
enough you need to get the full part the
complete part on or less you're good to
ever know in all URI or you're going to
have a URL that is bent that is not
readable which could not be uploaded to
the server a lot of boilerplate or
problem around that if you're naturally
doing it correctly now let's get look at
it quickly you have a projection
projection just when the column you're
looking at and we are looking at a video
media store the media data that's the
projection that the columns you looking
at now we call on the cursor which is
actually container for the data from the
circulated database now we're going to
do you need to query we need to query
the media stones we extract a particular
video or to extract the areas of videos
we are looking at so you call the get
Content resolver to query this method
and very needed and you pass it those
parameter you pass in the URL you pass
the projection the selection arguments
with its selection sort order and that's
it you have the URL which you already
about when you've selected the video you
have the projection which is the color
when you're talking about the selection
mode argument null and sort of the North
Bay's on daily preferences you need now
you test if the cursor is not equal to
Nala very good standard if it's not
already just return not it was much of
course not you move further yeah you
have to gather my point up the console
is not this can be if you've used a day
wrong format for the file manager for
picking the particular media so that's
just it now if you have the the cursor
which I for contents you need to get the
column index of choice you know just get
the index based on the column on the
column which is the projection I'll pass
that as an integer value and you need to
ET rate
move too fast at the pointy time and
after that you need to get the string
which is the column index over here
you need to pass that that's good to
actually convert so that's the real
value of the path that you're looking at
which is in string so you and it's how
you call the get part on the URA
it returns this string this string which
is extracted from the column index so
that just we'll be using for our up loop
now back to the upload we still have the
same format of sim our request school
will be the same map which takes in two
parameters the string and a request body
which is the ash Maurya so as we talked
about it when we are using the image now
I see average rather the generic hash
map which has an object over here which
you'll be using and instantiate the
video partner when you would have gotten
the real part from it so you have that
birthday in the file you convert that to
you it will fall to some so your father
will be useful which you serve as the
request body and other request body you
need to call the media type to pass are
you passing any form of media type which
actually takes them far as the second
parameter so you have that as a request
body and now you need to create a
structure of your map however you need
to put those values into the map now
what you're going to put you poured a
string which is going to be the volume
and also the request body which is
really what the the media type that you
you pass from the farm so you have that
right there and now you need to call the
API config
however you need to called retrofits
together is uploaded to the server we've
actually created that but in the
networking networking folder where you
have the API config the up convict and
server response I will do actually
declared the base URL at the end points
to get that done for us now after you
called in queue instachat the callback
which is the server response you need to
override two methods the on response and
your failure that's the response you
need from your server probably this is
our response or something Apple and it
filled on response you get the message
quickly test if it's successful and also
if the body of the message is not across
to know once you have that tests are
passed you need to extract the body and
get the message are from the body
definitely the message is good to be
explicit we've set that up where they're
from the server the kind of response we
are expecting in successful upload of an
image
it says well upload of the video it says
well blood of a PDF are that set up and
I've got actually good toast to the user
and that point to time maybe two I hate
the dialog you would have set up the
dialog to come up when you're uploading
if you do five because the video five
might be a little bit large so you
actually need a dialog so that's the
user could know that something is
uploading at the point in time to the
server needs to exercise patience for it
to get completed so once you have that
set up you have a successful message and
if not if there's a failure you get a
toast that there's a problem up loaded
into the image so you get something I
need to undo it
another point in time so that's just the
basic way to undo the video just like
we've done in the image actually of the
same flu and I hope you've been able to
understand this and you put this to
practice I will be uploading this or
school or create an appearance from this
because I have the first birth which are
takes care of the image now we'll get to
look at the video so our actually be
committed to the branch and I'll be
sharing the source code in the
description
always look at the description of the
video or YouTube to get our some details
about the video probably to get some
assets to work with to get the link to
the video or to get the link to the
source code and to get some order
helping details to help you through the
cause of the video or to the course of
the tutorial so insert is just for use
for your landing artists to actually
improve any aspects of how to try to
program it so thank you guys for hanging
out with the nurse studios I also be
showing the screencast and see let's see
how we're going to upload the video to
the server so this is going to be very
useful if you're creating this you made
the application if
during one or two days that deals with
uploading of image you could upload a
receipt of a customer you could upload
some files or things that the customer
needs to be uploaded to the server for
clarification so tank guys hanging out
with new traders video and please please
don't forget to subscribe to deliver
studios and have a wonderful time bye
for now