want to make a video application we can 想製作一個視頻應用程式, 我們可以
record flat back like this 像這樣記錄平背
well watch this tutorial 以及觀看本教程
welcome to knowledge app tutorials my 歡迎使用知識應用程式教程我的
name's Nigel this tutorial is going to 名稱的奈傑爾本教程將
show you how to build a video app the 教你如何建立一個視頻應用程式的
story will be based on a lot of the 故事將根據很多的
concepts from the previous how to create 從前面的概念如何創建
a camera app using intents so if I go 相機應用程式使用的意圖, 所以如果我去
too quickly on this tutorial you may 在本教程很快, 你可能會
want to look at that tutorial series 想看看這個教程系列
first let's make a start shall we let's 首先讓我們做一個開始, 我們應該讓我們的
create a new project called a video app 創建一個稱為視頻應用程式的新專案
I'm still using 5.0 I do need upgrade my 我仍然使用 5.0, 我需要升級我的
Nexus and use a blank tivity don't 連結和使用一個空白的活性不
needle with extra fluff I just add video 針額外的絨毛, 我只是添加視頻
app in front of this and finish now 應用程式在這之前, 現在完成
let's wait for it to build okay the 讓我們等待它建立好嗎
projects now completed its build its put 專案現已完成其建設其投入
me into the layout into the XML file I'm 我的佈局到 XML 檔, 我
the very first thing I want to do here 我想在這裡做的第一件事是
is visualize what the application is 是視覺化應用程式是什麼
going to look like so I'll do that from 要看起來像這樣, 我會做到這一點, 從
inside the layouts and basically I want 裡面的佈局, 基本上我想
to have my applications going to have a 我的應用程式將有一個
record button to record a video a play 記錄按鈕錄製視頻播放
button to play back what I recorded and 按鈕來播放我記錄和
it needs a video view just to display 它需要一個視頻視圖只是為了顯示
the recording so I'm going to go into 記錄, 所以我要進入
design here okay are the three sighs my 這裡的設計是三符號我
Augie okay I don't need to text whew 奧吉沒關係, 我不需要文字
that comes with the hello world text 伴隨著你好的世界文本
whew I can delete that first step is to 我可以刪除第一步是
add two buttons just drag-and-drop them 添加兩個按鈕只需拖放它們
first ones here I want to drag that to 第一個在這裡, 我想把它拖到
the bottom here one another button and 底部這裡一個另一個按鈕和
I'll drag and drop that here and also on 我將拖放在這裡, 也在
a video view to sit on top of the 一個視頻視圖坐在頂部的
buttons so let's see if I can find the 按鈕, 讓我們看看, 如果我能找到
video view is a video view 視頻視圖是視頻視圖
in drag that into this play and resize 在拖動到此播放和調整大小
it sits on top of the buttons because if 它坐在按鈕的頂部, 因為如果
we go into text you'll see it's a 我們進入文本, 你會看到這是一個
relative layout so you can adjust views 相對佈局, 以便您可以調整視圖
relative to each other on top underneath 相對的在上面的頂部
to the right off to the left off that's 右下到左關閉, 這是
what the relative layout gives us okay 什麼樣的相對佈局給我們好嗎
I'm happy with that but I do need to 我很高興, 但我確實需要
rename my buttons so I know which button 重命名我的按鈕, 所以我知道哪個按鈕
to press so this button here I'm going 按下這個按鈕, 我要去
to want to call record let's find the 要調用記錄, 讓我們找到
text for that I also want to change the 文本, 我也想改變
ID to give it a bit more of a context so ID 給它多一點的上下文, 所以
I just want to call it the record button 我只想把它叫做記錄按鈕
okay that's okay for me say yes to that 好吧, 沒關係, 我說是的,
I want to update all the references to 我要更新所有引用到
that ID okay the next step here is just 這個 ID 沒關係, 下一步是只是
to do the same for button two and I want 做同樣的按鈕二, 我想
to give button two an ID of play button 給按鈕兩個 "播放" 按鈕的 ID
and I want to change the text to display 我想更改要顯示的文本
okay I am now happier with the look and 好吧, 我現在更高興的外觀和
feel of what my application is going to 感覺我的應用程式將
look like if we pop into the text tab 看起來像如果我們彈出到文本選項卡
we'll see 我們會看到
yes we've got the two button views and 是的, 我們有兩個按鈕視圖和
our video view and you can see how 我們的視頻視圖, 你可以看到如何
relative views can align with the 相對視圖可以與
parents and you can also align like the 家長和您也可以像
video view to sit on top of one of the 視頻視圖坐在頂部的一個
buttons and it's also centering 按鈕, 它也居中
horizontal so hopefully the video views 水準, 所以希望視頻視圖
going to certain them at all okay so I'm 去肯定他們在所有沒關係, 所以我
now happy with that the next step I want 現在高興的是, 我想要的下一個步驟
to do is this start setting click 要做的是這個開始設置按一下
functionality to my buttons and the 功能到我的按鈕和
previous camera app tutorial we use the 以前的相機應用程式教程, 我們使用的
on clip functionality that was provided 在提供的剪輯功能上
to us by the button view and there's 我們的按鈕視圖, 並有
also an entire number of other methods 並且其他方法的整個數位
to add onclicklistener as well and so 添加 onclicklistener 以及等
I'm going to show you another method of 我要給你看另一種方法
how will you do that so we go into the 你將如何做到這一點, 所以我們進入
code so I go into the oncreate function 代碼, 所以我進入 oncreate 功能
where all the initialization happens up 所有初始化發生的地方
if it's me just go into my empty class 如果是我就進入我的空課
first I am going to need to create some 首先, 我將需要創建一些
variables for my buttons and for my 變數為我的按鈕和我的
video view first let me do the buttons 視頻視圖首先讓我做按鈕
and I'll create two variables for play 我會為遊戲創建兩個變數
and for the record and play button 記錄和播放按鈕
so first final to see in record few 所以第一次決賽看到在創紀錄的少數
another one will be in play whew okay 另外一個將在發揮, 好嗎
let's make it private 讓我們把它保密
okay and I'm going to do the same thing 好吧, 我會做同樣的事情
again here for the video view I think I 再次在這裡的視頻視圖, 我想我
just call this in video view so I'm 只是在視頻視圖調用這個, 所以我
happy with those buttons now I want to create 快樂的按鈕, 現在我想創建
I want to initialize my views from the 我要初始化我的視圖。
layout from the views from the layout 從佈局視圖中進行佈局
sunsets do that down here do you record 日落這樣做, 在這裡你記錄
view first and will initialize I record 首先查看並將初始化 I 記錄
view with the button from the layout you 使用佈局中的按鈕查看
have to cast at first so it's going to 首先要投, 所以它會
be record button and we'll do the same 是記錄按鈕, 我們會做同樣的
thing for the play button 遊戲按鈕的事情
and play button and let's initialize our 和播放按鈕, 讓我們初始化我們的
video view as well and again we need to 視頻視圖, 以及我們需要再次
cast that 投那
okay I've now initialized my views next 好吧, 我現在初始化我的觀點下
step is I want to create that on clip 步驟是, 我想創建在剪輯
functionality to my record button and my 功能到我的記錄按鈕和我的
play button and to do that we can add 播放按鈕, 並做到這一點, 我們可以添加
what's called a onclicklistener 什麼叫 onclicklistener
object and assign that set that up with 物件和分配, 該值設置為
our view you can do that with any of you 我們的看法, 你可以這樣做與任何人
so what's a set onclicklistener 那麼, 什麼是一個設置 onclicklistener
and then we create a new onclicklistener 然後我們創建一個新的 onclicklistener
object here do the wonderful magic of 這裡的物件做奇妙的魔術
Android studio it's already populated Android 工作室, 它已經填充
the function for me now let's do the 我現在的功能, 讓我們做的
same for the play button as well 同樣的播放按鈕, 以及
okay so we've now created our 好了, 所以我們現在已經創建了我們的
onclicklistener x' our buttons are now onclicklistener x ' 我們的按鈕現在
going to respond to key presses the next 要回應鍵按下
step is let's start working on our 步驟是讓我們開始工作, 我們的
record button our record buttons just 記錄按鈕我們的記錄按鈕只是
going to call an external application 要調用外部應用程式
that can record video so and we're going 可以錄製視頻, 所以我們要
to use the exact same methodology that 使用完全相同的方法,
we used in the camera and tenth video 我們使用的相機和第十視頻
app camera and tenth application the 應用相機和第十應用程式的
first thing here we want to create an 第一件事, 我們要創建一個
intense I should I call this intent 強烈的, 我應該叫這個意圖
um call video 調用視頻
and create a new intent 並創建一個新的意圖
create a new attempt as with the camera 使用觀景窗創建新嘗試
app we're going to actually have to 應用程式, 我們要實際上必須
provide an action so any video 提供操作, 使任何視頻
application that can play video will be 可以播放視頻的應用程式將被
able to respond to our intent so 能夠回應我們的意圖, 所以
and again we're going to use the media 再次, 我們要使用媒體
store and it's going to be the name of 商店, 它將是名稱
the action it's going to be called 它的行動將被稱為
action video capture pretty 動作視頻捕捉漂亮
self-explanatory 自我解釋
okay let's just talk a little bit about 好吧, 讓我們只是談談一點點關於
this action so every search for this 此操作, 因此每次搜索此
while Google and here in the media store 而谷歌和這裡的媒體商店
the developer's library click on that 開發人員的庫按一下該
and basically it says it's a standard 基本上它說這是一個標準
intent intent action that can be sent to 可以發送到的意向意向操作
have a camera application capture a 有一個相機應用程式捕獲一個
video for you so that's what I want I 視頻給你, 所以這就是我想要的, 我
want a application that can capture 希望能夠捕獲的應用程式
video to record a video for it and send 視頻錄製的視頻, 併發送
it back to my application back to the 它回到我的應用程式返回到
code okay so I've got my intent here 代碼好吧, 所以我有我的意圖在這裡
it's just a simple matter of starting an 這只是一個簡單的問題, 啟動一個
activity that will call our camera 活動, 將調用我們的相機
Application 應用
so start we use startactivityforresult 所以開始我們使用 startactivityforresult
in other words once we've called the 換句話說, 一旦我們調用了
camera application and it's finished 觀景窗應用和它的完成
capturing our video we want that 捕捉我們的視頻, 我們希望,
application to return back to us so 應用程式返回給我們, 所以
that's that activity for result we pass 這是我們通過的結果的活動
it on 10 that were just created and we 它在10剛剛創建, 我們
need to request code which we haven't 需要請求代碼, 我們還沒有
yet created so we'll create that creep 但創造, 所以我們將創造的蠕變
request code it's going to be another 請求代碼這將是另一個
variable quest codes and nuts and I'll 可變的追求代碼和堅果, 我會
call it a tip pity start camera 稱它為提示憐憫啟動攝像頭
and assign a value of zero and we'll put 並分配一個值為零, 我們將把
that into our start activity request 到我們的開始活動請求
and that's it for the for recording our 這是為記錄我們的
video okay now the next step here is 視頻好了, 現在下一步是
once through videos being kept and 一旦通過視頻被保存和
returned back to our application we need 回到我們的應用程式, 我們需要
to capture the response and an on 捕獲回應和 on
activity result function so let's put 活動結果函數讓我們把
that in there 在那裡
and the first one is our request code 第一個是我們的請求代碼
second is going to be the result code 第二個將是結果代碼
whether or not the whether or not the 是否該
request was successful and the third 請求成功, 第三個
one's going to be an intent returned 一個將是一個意圖返回
back to us that's going to contain the 回到我們將包含的
location of the video that was captured 捕獲的視頻位置
that would be an intent we call it data 這將是一個意圖, 我們稱之為資料
okay so first thing first is we just put 好吧, 首先是我們只是把
a bit of filtering code to make sure we 一些過濾代碼, 以確保我們
are getting a successful result and our 取得了成功的結果, 我們的
request code back so if we quest code 請求代碼回來, 所以如果我們尋求代碼
equals 2 to start camera wrap and of 等於2開始相機包裝和
result code equals result okay we will 結果代碼等於結果好吧, 我們會
then process what's happened and we're 然後處理發生了什麼事, 我們是
not sign-in when comparing it okay so 不登錄時, 比較沒關係, 所以
the next step here is to actually inside 接下來的步驟是在裡面
the intent data argument we have that 目的資料參數, 我們有,
that will provide us with the URI of the 這將為我們提供的 URI
location of the video image that was 視頻圖像的位置
captured by the video application so we 捕獲的視頻應用程式, 所以我們
need to create a URI 需要創建 URI
variable so it's a video you are I and 變數, 所以它是一個視頻, 你是我和
from here we can use the data 從這裡我們可以使用資料
get data function so this get data 獲取資料函數, 以便獲取資料
function is actually returned to us the 函數實際上是返回給我們的
URI of whether video was captured and 是否捕獲視頻的 URI 和
after that is just a simple matter of 之後, 只是一個簡單的問題
signing that URI to our actual video 將 URI 簽名到我們的實際視頻
view so set video URI pretty 視圖, 所以設置視頻 URI 漂亮
self-explanatory and we pass it the URI 自我解釋, 我們通過它的 URI
that we just set up okay let's now 我們只是設置好了, 讓我們現在
happen so once we've captured the video 發生, 所以一旦我們抓住了視頻
we want to start playing the video so we 我們想開始播放視頻, 所以我們
need to call that in a place where we're 需要調用它在一個地方, 我們是
going to call that it's going to be from 要調用, 這將是從
the play button so if we go back up to 播放按鈕, 所以如果我們回到
the play button okay I made a little 播放按鈕好吧, 我做了一個小
boo-boo the code that goes into the 噓噓代碼進入
record I've put into the play so we're 記錄, 我已經把這齣戲, 所以我們
just going to move that few lines of 只是要移動這幾行
code and put it into record and then in 代碼, 並把它記錄在案, 然後在
order to play properly so from Lions 41 為了正確發揮, 所以從獅子41
to 44 we just need to cut and paste 到 44, 我們只需要剪切和粘貼
and go up to here 然後到這裡來
and the space below so out so we've now 和下面的空間, 所以我們現在已經
fixed our record button let's go into 修正了我們的記錄按鈕, 讓我們進入
the play button and add the code that 播放按鈕, 並添加代碼,
actual will play the video so we need to 實際將播放視頻, 所以我們需要
in video view and it's just a matter of 在視頻視圖, 這只是一個問題的
courting start just a quick check on the 求愛開始只是一個快速檢查
right hand side so you've got any red 右手邊, 所以你有任何紅色
bars for any errors this looks okay okay 酒吧的任何錯誤, 這看起來不錯好嗎
so this looks okay let's try running the 所以這看起來不錯, 讓我們嘗試運行
application and see what happens 應用程式, 看看會發生什麼
now as usual I'm going to record that so 現在像往常一樣, 我要記錄, 所以
applications now started that's what 應用程式現在開始, 這是什麼
this is what it looks like so we'll 這是什麼樣子, 所以我們會
press the record button we've started up 按下我們開始的記錄按鈕
a camera application I'm just going to 一個相機應用程式, 我只是要
switch it and I'm just going to video I 切換它, 我只是去視頻我
will it's enough accept that okay 這是否足夠接受, 好嗎
applications now it's gone back to our 應用程式現在它已經回到我們的
application let's click play and see 應用程式讓我們點擊播放, 看看
what happens and we are now playing back 發生了什麼, 我們現在玩回
the video that we recorded and that's 我們錄製的視頻, 這是
that that's what we wanted our 這就是我們想要的
application to do okay as with the 應用程式做沒關係, 因為與
normal flow of these tutorials we're 這些教程的正常流程, 我們
going to debug we're going to set up 要調試, 我們要設置
some breakpoints and step through the 一些中斷點並逐步通過
lines of code to actually see what we've 程式碼, 以實際看到我們已經
done okay so I want to set up one and 做得好, 所以我想建立一個和
the oncreate that's where we've created 我們創造的 oncreate
our variables one here I want to put on 我們的變數之一, 在這裡我想穿上
one in the on Requip activity request so 一個在 Requip 活動請求, 所以
we see what happens to the Crest request 我們看到波峰請求會發生什麼
whether it's successful or not and I 無論成功與否, 我
also want to put some with our view on 也想把一些與我們的看法
click listeners let's put one on here 按一下攔截器讓我們把一個在這裡
for the record we'll put one on here for 記錄, 我們會把一個在這裡
the view and that should be it that's 的看法, 應該是它的
enough Brett points so we click on the 足夠的佈雷特點, 所以我們點擊
debug button 調試 "按鈕
and before the application fully 在應用程式完全
initializes and turns on we've already 初始化和打開我們已經
had our first breakpoint in the oncreate 有我們的第一個中斷點在 oncreate
step for that so we assign our record 步驟, 所以我們分配我們的記錄
view button with the view from the 視圖按鈕。
layout same for the play button and the 佈局相同的播放按鈕和
video view we sign it with the video 視頻視圖我們簽署它與視頻
view from the layout now we create our 視圖從佈局現在我們創建我們的
own click listeners for the record 自己的點擊攔截器記錄
button and the play button and that's it 按鈕和播放按鈕, 這就是它
this continue on my applications now 現在繼續我的應用程式
start and now can start operating my 開始, 現在可以開始操作我的
application first step is to record and 應用程式的第一步是記錄和
I've put another breakpoint here and the 我在這裡放了另一個中斷點和
first one is the record button here we 第一個是記錄按鈕, 我們在這裡
know our on click listeners working okay 知道我們的點擊攔截器工作正常
so we create our intent we give it an 所以我們創造我們的意圖, 我們給它一個
action to call an external video 調用外部視頻的操作
application then we start that 應用程式然後, 我們開始,
application and continue on so the video 應用程式, 並繼續這樣的視頻
application of called has responded and 調用的應用已作出反應, 並
the started so you can press the record 開始, 所以你可以按下記錄
button and record a war stop that 按鈕和記錄的戰爭停止,
except that and I've had another 除了, 我已經有了另一個
breakpoint applications no longer 中斷點應用程式不再
running we're not on activity result so 運行, 我們不是在活動結果, 所以
applications returned back to us so we 應用程式返回給我們, 所以我們
can step through the code the first part 可以單一步驟代碼第一部分
is let's check to see if it's our 是讓我們檢查, 看看它是否是我們的
request it is ok from there we can 要求它是 ok, 從那裡我們可以
actually get the location of the where 實際上得到的位置的地方
the videos been saved to by the URI 視頻已由 URI 保存到
and and then we just assign once we've 然後, 我們只是分配一旦我們已經
got the URI we can just assign that URI 得到了 uri, 我們可以只分配該 uri
to the video view 到視頻視圖
okay now we've gone back to our 好了, 現在我們已經回到我們的
application so nothing's going to happen 應用程式, 所以什麼都不會發生
yet until I press play and soon as I 然而, 直到我按下播放, 很快, 因為我
press play 新聞播放
we've gone back into onclicklistener 我們回到了 onclicklistener
here which is the for the play button so 這裡是播放按鈕, 所以
nothing's going to happen until I hold 什麼都不會發生, 直到我抓住
my shaky hand for you to see and press 我顫抖的手, 你看, 並按
go again and we can see a bit of 再來一次, 我們可以看到一些
movement of a picture of a video of a 一個視頻的圖片移動
wall and that is it so what we learnt in 牆, 這是它, 所以我們學到的
this tutorial is we learnt there's 本教程是我們學到有
alternative ways of creating the click 創建按一下的其他方法
events to listen to views when a user 事件來偵聽使用者的視圖
presses on them we also use the learnt a 按在他們身上, 我們也使用學到的
new intent action that allows us to call 新的意圖行動, 讓我們調用
external video applications we got 我們得到的外部視頻應用程式
introduced to your you are eyes and how 介紹給你你的眼睛和如何
you can loader your I create URI and 你可以裝入你的我創建 URI 和
assign that to a video view and then 將該值分配給視頻視圖, 然後
once you've got a video view you just 一旦你有一個視頻視圖, 你只是
have to call play on it to play that 必須調用發揮它發揮
content and so that's all for this 內容, 所以這一切都是為了這個
Tutorial 教程
most of this tutorial was based on the 本教程的大部分是基於
previous tutorial the camera application 上一篇教程攝像機應用
using intents but I wanted to go through 使用意圖, 但我想去通過
this one at a bit of a faster pace and 這是一個有點快的速度和
it's just a bit of a refresher of what 這只是一點點的複習什麼
we learnt in that past video tutorial 我們在過去的視頻教程中學到了
series if you like these tutorials don't 系列, 如果你喜歡這些教程不
forget to subscribe and I do have a big 忘記訂閱, 我有一個大
list in my mind of future content to 清單在我心目中的未來內容
publish as well that's all for this one 發佈以及這是所有這一個
bye for now 再見
and take a photo of a cup of green tea 拍一杯綠茶的照片
Again 再次
and we have the actual image itself 我們有實際的圖像本身
effectively nothing's changed from the 實際上什麼都沒有改變從
previous tutorial except what I expect 以前的教程, 除了我的期望
to see here is this but this flip map 看到這裡是這個, 但這個翻轉地圖
emerge greatly reduced that we're not 出現大大減少, 我們不
taking up too much rather the system 占了太多, 而系統
everything happy with our phone ok we 所有的快樂與我們的電話 ok, 我們
can stop recording now 現在可以停止錄製