May
18th,
2012
在iOS要撥放影片其實有兩種播放器的source可以使用。
一個就是Media Player (MPMoviePlayerController),另一個是AVPlayer (AV Foundation)。
這裡會介紹一些簡單使用Media Player的相關程式碼。
主要有幾個部分,第一個部份就是設定撥放來源,在這裡是使用網路上的檔案。
接下來的部分就是關於撥放得相關設定
//強迫旋轉你的iDevice (這裡是橫放)
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
// 設定撥放器的外觀
[WebPlayer setControlStyle:MPMovieControlStyleFullscreen];
[WebPlayerr setFullscreen:YES];
//設定影片比例的縮放、重複、控制列等參數
//影片旋轉90度
WebPlayer.view.transform = CGAffineTransformMakeRotation(1.5707964);
WebPlayer.scalingMode = MPMovieScalingModeAspectFit;
WebPlayer.repeatMode = MPMovieRepeatModeNone;
//將影片加至主畫面上
WebPlayer.view.frame = self.view.bounds;
[self.view addSubview:WebPlayer.view];
//開始播放
[WebPlayer play];
這樣其實就可以撥放全螢幕的影片並且將手機橫放
如果播放完影片要可以回到原來的畫面,則要多接收一個Observer.
// 註冊endPlay 當撥放完畢的時候,會收回傳的通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(endPlay:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:WebPlayer];
最後就是放endPlay的所有內容,裡面的重點在釋放撥放器與回到iDevice相關設定
-(void)endPlay: (NSNotification*)notification
{
//解除註冊回傳
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:WebPlayer];
//將你的iDevice 轉回來
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
//停止播放
[WebPlayer stop];
//Release control
[WebPlayer release];
//現在的view 移除~ 回到原本的view
[WebPlayer.view removeFromSuperview];
}
參考文章:
Furnace iOS 程式設計中文學習網站: 使用_MPMoviePlayerController_
MPMoviePlayerController 與MPMoviePlayerViewController
[Iphone中利用_MPMoviePlayerController_線上播放視頻(轉) @ OPEN](http://fecbob.pixnet.net/blog/post/36635972-iphone%E4%B8%AD%E5%88%A9%E7%94%A8mpmovieplayercontroller%E7%B7%9A%E4%B8%8A%E6%92%AD%E6%94%BE%E8%A6%96%E9%A0%BB(%E8%BD%89)
繼續閱讀
May
6th,
2012
Finally, I decide to release the source code of my Windows Phone Google Reader App.
Please feel free to https://xreadr.codeplex.com/ here.
Here is my project summary:
Project Description
XReadr is a simple Windows Phone 7 app using Google Reader API.
It already has login, browse and mark it as read function here.
XReadr is simple Windows Phone 7 App which using Google Reader API.
It also has follow function:
Login page which using HttpWebRequest
Browse Unread Labels
Browse every news on Label
I also put the first draft of source code, I hope it could help all of you which want to write more Windows News App here.
More implementation detail about how Windows Phone to use Google Reader API, please refer my blog here:
http://www.evanlin.com/blog/archives/001138.html
http://www.evanlin.com/blog/archives/001139.html
It write by Traditional Chinese, feel free to ask me via English.
繼續閱讀
May
2nd,
2012
這幾天開始把原來的RSS Reader APP程式多加頁面後,發現了一些小問題。網路上或許還算是好找。
但是我稍微整理一下,其實Pou’s blog兩篇文章有相當清楚的解釋
Windows Phone 7 - 動態轉換初始的Default Page
Windows Phone 7 – Navigation Framework原理概論
在此只把常遇到的兩個問題整理一下:
如何改變初始頁面(How to change default page on Windows Phone)
修改文件”WMAppManifest.xml”以下程式碼:
<Tasks>
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks>
如何在頁面中傳遞參數(How to pass parameter over pages on Windows Phone)
在頁面間傳遞參數可以把它當成是網頁的GET模式(就是?Param_1=value_1&Param_2=value_2)
在原來的頁面可以用以下的指令傳遞
string mylogin = "/Page2.xaml";
mylogin += "?Param1=" + "VALUE1";
mylogin += "&Param2=" + "VALUE2";
if (!String.IsNullOrWhiteSpace(mylogin))
{
this.NavigationService.Navigate(new Uri(mylogin, UriKind.Relative));
}
再接收的Page2就必須要有以下的方式去接受參數
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
//Get parameter
string myParam1 = NavigationContext.QueryString["Param1"];
string myParam2 = NavigationContext.QueryString["Param2"];
}
這樣就可以了~~~
參考網頁:
http://www.eugenedotnet.com/2011/03/passing-values-to-windows-phone-7-pages-uri-paremeters-or-querystring/
http://stackoverflow.com/questions/3892271/how-do-i-change-the-startup-page-on-a-wp7-silverlight-app
http://www.dotblogs.com.tw/pou/archive/2011/06/05/27148.aspx
http://www.dotblogs.com.tw/pou/archive/2011/04/30/23929.aspx
http://www.dotblogs.com.tw/pou/archive/2011/01/23/20967.aspx
繼續閱讀
April
29th,
2012
3. 瀏覽全部尚未閱讀的列表 接上篇文章,接下來會開始講解如何去獲得使用者所有標籤(Label)的文章。 一開始首先一樣是先提供這裡會用到的相關Google Reader API的講解 > > [https://www.google.com/reader/api/0/unread-count?allcomments=true&output=json&ck=12121&client=scroll](https://www.google.com/reader/api/0/unread-count?allcomments=true&output=json&ck=12121&client=scroll) > > 你就可以在瀏覽器上面獲得你要的資訊。你如果有登入你可能會獲得像是以下的一些資料。 接下來是取得資料的相關原始碼: public void GetGoogleReaderUnReadCount() { string auth_params = string.Format("https://www.google.com/reader/api/0/unread-count?allcomments=true&output=json&ck=" + DateTime.Now.Ticks.ToString() + "&client=scroll"); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(auth_params); httpRequest.Method = "GET"; httpRequest.Headers["Authorization"] = "GoogleLogin auth=" + UserAuth; httpRequest.Headers["Cookie"] = "SID=" + UserSid; httpRequest.BeginGetResponse(new AsyncCallback(ResponseCallbackInner), httpRequest); } 抓回資料後,就開始要去parse這些資料,這邊會用到大量的JSON相關技巧,我也盡量試著解釋清楚一點給大家知道。首先,會拿到以下的資料,以下是以我的資訊當作範例~跟你拿到的可能會有點差異。 { "max":1000, "unreadcounts":[ { "id":"user/-/label/教學網站", "count":9, "newestItemTimestampUsec":"1335595557150290" }, { "id":"user/-/label/Funny", "count":83, "newestItemTimestampUsec":"1335621983685977" }, { "id":"user/-/label/專業評論", "count":38, "newestItemTimestampUsec":"1335617137314302" } } 這些資料就是JSON的資料,關於JSON是甚麼與JSON.NET該怎麼使用的部分,網路上有許多相關的程式碼,我這裡就不詳述了。 根據上面資料排序的結果,我們需要去抓unreadcounts下面的子結點,而他的資料格式如下: public class ServerUnreadResult //JSON { public string id { get; set; } public string count { get; set; } public string newestItemTimestampUsec { get; set; } } 所以在我們程式碼中,就是可以依照以下的安排: private void ParseUnreadList(string responseString) { //JSON Parse JObject googleSearch = JObject.Parse(responseString); // get JSON result objects into a list IList<JToken> results = googleSearch["unreadcounts"].Children().ToList(); // serialize JSON results into .NET objects IList<ServerUnreadResult> searchResults = new List<ServerUnreadResult>(); foreach (JToken result in results) { ServerUnreadResult searchResult = JsonConvert.DeserializeObject<ServerUnreadResult>(result.ToString()); //Parse the label name // ex: user/06771113693638414260/label/Win8 string...
繼續閱讀
April
28th,
2012
這個禮拜初,最後總算弄好標記閱讀(Mark Read)後,Google Reader App總算也完成了。不過由於接下來可能會把一些時間拿去研究iOS。最後決定把這部份的研究做一個總整理。這一篇文章會包括以下的技術: Google API 在Windows Phone 7.1上面的相關使用 對於Google Reader API的JSON的相關使用 一些簡單的Windows Phone原始碼(source code)的討論 關於RSS Reader App: 首先我想在這裡先稍微整理一下,一個簡單的RSS Reader的Windows Phone APP是相當簡單的。其實只要會簡單的Webclient加上去使用內建的資料格式就可以完成,這裡微軟也提供完整的原始碼與介紹。本篇介紹的部分主要都是專注在Google Reader的部分。 Google Reader API: 由於我是在Windows Phone上面做開發(Windows Phone 7.1)所以無法直接使用Google Data上面的相關API,在這裡也要特別解釋,如果你只是WPF或是一般Windows程式~ 你可以直接使用Google Data而不需要一步步的完成Google Reader API的部分,在這裡把之前文章列過的Google Reader API整理一次: Unofficial Google Reader API R2 google reader on Google code pyfeed on Google code 一個簡單Google Reader APP的流程: 接下來我會用碼個Google Reader 會使用到的流程來介紹該如何去撰寫,首先一個Google Reader APP會有以細的流程: 登入,也就是登入你的Google Reader 帳號 取得登入者的相關資訊 瀏覽全部尚未閱讀的列表 打開某個標籤(Label)內去看裡面還沒閱讀的文章 打開該文章網站並且將其標記已經閱讀(mark as read) 接下來我會針對以下的部分,開始整理一些原始碼: 1. 登入,也就是登入你的Google Reader 帳號 在這裡會使用到基本的Google 登入部分,你可以直接在你的瀏覽器上頭打入以下的鏈結。 > > [https://www.google.com/reader/api/0/token?ck=212121212&client=scroll](https://www.google.com/reader/api/0/token?ck=212121212&client=scroll) > > 稍微解釋一下參數: > > ck: 就是時間標記(timestamp),你可以用DateTime.Now.Ticks.ToString()拿到 > > > > client:先填入scroll的方式 > > 如果你已經登入過的話,一樣會有一樣的結果 public void LoginGoogleReader() { string email = "YOUR_EMAIL"; string passwd = "YOUR_PASSWORD"; string auth_params = string.Format("https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email=" + email + "&Passwd=" + passwd + "&service=reader&source=J-MyReader-1.0"); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(auth_params); <font color="#ff0000"> httpRequest.Method = "POST";</font> RequestState myRequestState = new RequestState(); myRequestState.request = httpRequest; IAsyncResult result = (IAsyncResult)httpRequest.BeginGetResponse(new AsyncCallback(AuthRespCallback), myRequestState); } 但是你也需要去把登入回來的SID與AuthID去parse出來,以下提供相關方法: private void ParseLogin(string responseString) { string[] arrs =...
繼續閱讀
April
25th,
2012
上一篇文章有講解利用HttpWebRequest的方式來完成Google Reader中的標記閱讀,但是因為edit-tag本身就不屬於太消耗時間的動作。與其去用HttpWebRequest的非同步的方式,不如使用容易又好用的WebClient,所以我就把我原來程式碼做了一點修改。
public void MarkArticleAsRead()
{
CurrentTransType = Transaction_Type.MARK_AS_READ;
string auth_params = string.Format("https://www.google.com/reader/api/0/edit-tag?client=scroll&format=joson&ck=" + DateTime.Now.Ticks.ToString());
string postData = "";
postData += "&i=tag:google.com,2005:reader/item/fa42c976c848ecf4";
postData += "&a=user/-/state/com.google/read";
postData += "&s=feed/http://funiphone.pixnet.net/blog/feed/rss";
// Note the token must get within 30 mins
postData += "&T=//mUESPUMtDyZh6BaFXd-CqQ";
WebClient wc = new WebClient();
wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
wc.Headers["Authorization"] = "GoogleLogin auth=" + UserAuth;
wc.Headers["Cookie"] = "SID=" + UserSid;
try
{
wc.UploadStringAsync(new Uri(auth_params), "POST", postData);
}
catch (WebException e)
{
//handle error if any
}
}
<font face="Georgia">幾個需要注意的地方如下:</font>
UserAuth與UserSid 需要先對Google API做login的部分
Content-type是必須要先填成這樣,我試過uff8會失敗~
繼續閱讀