NSURL的用法

1:NSURL初始化方法:

[csharp] view plaincopy
  1. NSURL *url=[NSURL URLWithString:@"http://www.baidu.com?id=1"];  


2:解决NSURL初始化失败的方法.

将传进来的NSString 进行 UTF8 转码即可.

[csharp] view plaincopy
  1. NSString *strLocalHtml = @"file:///Users/amarishuyi/Desktop/My IPhone Life/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html";  
  2. strLocalHtml = [NSString stringWithFormat:@"%@?Value=%@",strLocalHtml,self.txtUrl.text];  
  3. strLocalHtml= [strLocalHtml stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  4. NSURL * url=[NSURL URLWithString:strLocalHtml];  

3:NSURL 成功初始化后可以获取的参数 (摘自:NSURL 学习 )


[csharp] view plaincopy
  1. NSURL *url = [NSURL URLWithString:  @"http://www.baidu.com/s?tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709"];     
  2. NSLog(@"Scheme: %@", [url scheme]);    
  3. NSLog(@"Host: %@", [url host]);    
  4. NSLog(@"Port: %@", [url port]);        
  5. NSLog(@"Path: %@", [url path]);        
  6. NSLog(@"Relative path: %@", [url relativePath]);   
  7. NSLog(@"Path components as array: %@", [url pathComponents]);           
  8. NSLog(@"Parameter string: %@", [url parameterString]);      
  9. NSLog(@"Query: %@", [url query]);          
  10. NSLog(@"Fragment: %@", [url fragment]);  
  11. NSLog(@"User: %@", [url user]);  
  12. NSLog(@"Password: %@", [url password]);  

结果如下:

[csharp] view plaincopy
  1. 2012-03-31 18:22:20.904 SmallDemoList[5473:11603] 12131232  
  2. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Scheme: http  
  3. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Host: www.baidu.com  
  4. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Port: (null)  
  5. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Path: /s  
  6. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Relative path: /s  
  7. 2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Path components as array: (  
  8.     "/",  
  9.     s  
  10. )  
  11. 2012-03-31 18:22:20.916 SmallDemoList[5473:11603] Parameter string: (null)  
  12. 2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Query: tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709  
  13. 2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Fragment: (null)  
  14. 2012-03-31 18:22:20.917 SmallDemoList[5473:11603] User: (null)  
  15. 2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Password: (null)  

4:根据文件名称和文件后缀获取程序包内容文件的路径

NSURL *urlKindEditor = [[NSBundlemainBundleURLForResource:@"simple"withExtension:@"html"subdirectory:@"KindEditor/examples"]; 


URLForResource:文件名称

withExtension:文件后缀

subdirectory:在程序包中的哪个子目录中寻找. 

如果没有找到将会返回nil

找到后返回如下路径: file://localhost/Users/amarishuyi/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/FB0CDABC-D0E2-45FF-AA2C-959E8A65ADB4/SmallDemoList.app/KindEditor/examples/simple.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
音频、视频播放相关类的使用方法可以分为以下几个步骤: 1. 导入相关库 在使用音视频播放功能之前,需要先导入相关的库,常用的有AVFoundation、MediaPlayer、AVKit等。 2. 创建AVPlayer对象 AVPlayer是音视频播放的核心类,通过它可以控制音视频的播放、暂停、快进、快退等操作。创建AVPlayer对象的代码如下: ``` NSURL *url = [NSURL URLWithString:@"http://example.com/example.mp4"]; AVPlayer *player = [AVPlayer playerWithURL:url]; ``` 3. 创建AVPlayerLayer对象 AVPlayerLayer是AVPlayer的显示层,用于展示视频内容。创建AVPlayerLayer对象的代码如下: ``` AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; playerLayer.frame = self.view.bounds; [self.view.layer addSublayer:playerLayer]; ``` 这里将AVPlayerLayer添加到了self.view的layer上,如果需要将视频展示在特定的UI控件上,可以将playerLayer添加到该UI控件的layer上。 4. 操作AVPlayer对象 创建AVPlayer对象和AVPlayerLayer对象之后,就可以对AVPlayer对象进行操作了,比如播放、暂停、快进、快退等操作。常用的操作代码如下: ``` [player play]; // 播放 [player pause]; // 暂停 [player seekToTime:CMTimeMakeWithSeconds(10, 1)]; // 快进到第10秒 [player seekToTime:CMTimeMakeWithSeconds(10, 1) completionHandler:^(BOOL finished) { // 快进完成后的回调 }]; ``` 以上就是音频、视频播放相关类的使用方法,希望对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值