網頁

2012年8月10日 星期五

iOS開發筆記 - app內直接播放YouTuBe影片

最近有個需要,客戶想要做到的效果是YouTuBe影片在iOS上能
1. 在原有的app中執行,不可離開
2. 全螢幕
3. 橫向看

我的方式是先加入一個ViewController ,命名為YouTuBeController,為了設成橫向,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == (UIDeviceOrientationLandscapeLeft) );
}

再來是要加入YouTuBe影片,用WebView來載入,我拿足球影片來當範例(取得影片的url,請參考我最底下網址參考的最後一個link,有官方說明)程式碼如下:

UIWebView *youTubeWebView = nil;
if (youTubeWebView == nil) {
        UIScreen *screen = [UIScreen mainScreen];
        CGRect frame = [screen applicationFrame];
        youTubeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, frame.size.height, frame.size.width)];
        youTubeWebView.delegate = self;
}

NSString* embedHTML = @"\ 
    <html><head>\ 
    <style type=\"text/css\">\ 
    body {\ 
        background-color: transparent;\ 
        color: white;\ 
    }\ 
    </style>\ 
    </head><body style=\"margin:0\">\ 
   <iframe width=\"%0.0f\" height=\"%0.0f\" src=\"%@?rel=0\" frameborder=\"0\" allowfullscreen></iframe> \
    </body></html>";
    
    NSString* html = [NSString stringWithFormat:embedHTML, youTubeWebView.frame.size.width, youTubeWebView.frame.size.height, @"http://www.youtube.com/embed/yGS6F-buYZw"];

[youTubeWebView loadHTMLString:html baseURL:nil];
self.view = youTubeWebView; //將view設成剛建好的webview

參考網址
How To Play YouTube Videos Within an Application
How to play youtube movie?
How to Watch YouTube Videos on Your iPhone
YouTube APIs + iPhone = Cool mobile apps

官網:
如何嵌入 YouTube 影片

2012年7月30日 星期一

iOS開發筆記 - UIFont的設定

先來個簡單的Example,在設定Lable時常會用到

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(110, 35, 180, 30)] autorelease];
label.text = @"測試";
label.font = [UIFont fontWithName:@"Arial-BoldMT" size:20]; //設定粗字體
label.textColor = [UtilFuncs transferHexColorCode:@"#50860e"];
label.backgroundColor = [UIColor clearColor];


在iOS中,沒有設定粗體這東西,完全要靠字體本身,所以上述Example才會用Arial-BoldMT,不過我想這才是正常的做法吧。



參考網址:
https://discussions.apple.com/thread/1533499?start=0&tstart=0

2012年7月28日 星期六

Android開發筆記 - Google AdMob的官方文件及jar file網址

做個記錄

https://developers.google.com/mobile-ads-sdk/docs/android/fundamentals?hl=zh-TW#requirements

Android開發筆記 - 若是有用到project是library,千萬別隨便升級,記得備份

上一篇:Android開發筆記 - Could not find class 'com.google.ads.AdView'有談到class not found的問題是ADT升級的問題,但我的專案是好幾個project的dependency及admob的jar file集合,雖然知道在libs上加入jar file,直接在每個project的compiler好的jar file,但不知為何的,反而告知找不到本身project的class。


經過了幾乎是一整個星期的反覆查證及測試,最後我只能回復到我以往的版本,拿出以前的備分,重新來過,Admob記得回到4.1.1,因為4.3.1需要3.2的支援,3.2需要升級到至少1.6,沒想到花了這麼長的時間,沒解法,也許在哪天就想出來了吧


[更新事項]
備份目標
1. eclipse本身的folder,主要是plugin要備份
2. android sdk備份
3. workspace的code,記得.meta這個folder刪掉


參考網站:
http://wazai.net/2199/android-sdk-r17-noclassdeffounderror
http://stackoverflow.com/questions/10026936/eclipse-adt-17-and-the-libs-folder
http://hi.baidu.com/545057627/item/eec9a6cd5e142003b77a24fd
http://www.imobilebbs.com/wordpress/?p=2947
http://shareandopen.tumblr.com/post/25650390953/android-run-and-get-java-lang-verifyerror
http://www.oschina.net/question/40576_45439



2012年7月23日 星期一

Android開發筆記 - Could not find class 'com.google.ads.AdView'

這陣子升級了android的sdk後,admob就開始有問題了,出現了這個字眼

Could not find class 'com.google.ads.AdView'

真的是令人煩悶的東西,每每更新了sdk,就得找找有沒有什麼trouble,不過唸歸唸,還是得解決。後來找到了,在Android tool r17以後,要在android project上加入libs這個folder(這邊有個要注意的,記得將它變成source folder的屬性),然後將你的admob的jar實際copy過去,就可以順利讀到這個class了

參考網頁:
http://stackoverflow.com/questions/10523703/error-inflating-class-com-google-ads-adview