2012-12-18 44 views
8

Tôi đã thử phát một video .mp4 từ một trang web (với Thẻ video HTML5) bằng UIWebView. Thiết bị và mô phỏng iPhone/iPad chỉ hiển thị khung màu đen có nút phát được phát. Nếu tôi vừa gọi trang web này trên phiên bản Safari Mac, bạn có thể chơi nó. Có vấn đề gì không?UIWebview không phát mp4 Video

Đây không phải là tệp cục bộ. Html trông giống như sau:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta charset="utf-8" /> 
     <link rel="stylesheet" type="text/css" href="../css/shared-culture.css" /> 
    </head> 
    <body> 
     <section class="base"> 
      <hgroup> 
       <h1>creative commons</h1> 
       <h2>a shared culture</h2> 
      </hgroup> 

       <p>To celebrate our 2008 fundraising campaign, Creative Commons has 
        released “A Shared Culture,” a short video by renowned filmmaker <a 
         href="http://en.wikipedia.org/wiki/Jesse_Dylan">Jesse Dylan</a>. Known for 
        helming a variety of films, music videos, and the Emmy Award-winning <a 
         href="http://my.barackobama.com/page/invite/yeswecanvideo">“Yes We Can”</a> 
        Barack Obama campaign video collaboration with rapper will.i.am, Dylan created 
        “A Shared Culture” to help spread the word about the Creative Commons mission. </p> 
       <!-- height="240" width="360" --> 
       <video id="video1" controls="controls"> 
        <source src="../video/shared-culture.mp4" type="video/mp4"/> 
        <source src="../video/shared-culture.webm" type="video/webm"/> 
        <div class="errmsg"> 
         <p>Your Reading System does not support (this) video.</p> 
         <pre><code> 
&lt;video id="video1" controls="controls"&gt;      
    &lt;source src="../video/shared-culture.mp4" type="video/mp4"/&gt; 
    &lt;source src="../video/shared-culture.webm" type="video/webm"/&gt;  
&lt;/video&gt; 
         </code></pre> 
        </div> 
       </video> 
       <p>In the video, some of the leading thinkers behind Creative Commons 
        describe how the organization is helping “save the world from failed sharing” 
        through free tools that enable creators to easily make their work available to 
        the public for legal sharing and remix. Dylan puts the Creative Commons system 
        into action by punctuating the interview footage with dozens of photos that have 
        been offered to the public for use under CC licenses. Similarly, he used two 
        CC-licensed instrumental pieces by Nine Inch Nails as the video’s soundtrack 
        music. These tracks, “17 Ghosts II” and “21 Ghosts III,” come from the Nine Inch 
        Nails album Ghosts I-IV, which was released earlier this year under a Creative 
        Commons BY-NC-SA license. (See <a 
         href="http://creativecommons.org/videos/a-shared-culture">attribution</a>.) 
       </p> 

     </section> 

    </body> 
</html> 
+0

là video từ tệp cục bộ, bạn có thể đăng mã 'HTML' của mình không. – arthankamal

+0

Nếu bạn chỉ muốn phát video trong trang web đó, hãy xem [VideoPlayerKit] (https://github.com/ign/VideoPlayerKit). –

+1

Chỉ cần xem nguồn trang tại 'http://my.barackobama.com. . ./video/shared-culture.mp4' và nó tuyên bố thẻ nhúng phim với thuộc tính: 'type =" application/x-shockwave-flash "'. Đối với Apple HLS, bạn cần H.264/AVC trong vùng chứa MPEG2.TS. Tài liệu HLS tại đây: https://developer.apple.com/resources/http-streaming/ –

Trả lời

2

Nghe giống như sự cố codec. Bạn có thể xem những gì codecs các tập tin sử dụng nếu bạn mở nó trong VLC trên máy tính của bạn, vào Window-> Media Information-> Codec Details. Câu trả lời here liên kết đến các tài liệu của Apple, nơi bạn sẽ tìm thấy được hỗ trợ video và codec âm thanh:

https://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html

9

Nó có thể không được trong một định dạng iPhone thân thiện.

Kéo file mp4 vào iMovie và sau đó bấm vào Share ->Export Movie và chọn một trong các định dạng tương thích với iPhone.

+0

Tôi đã phải mã hóa lại video của mình bằng Adobe Media Encoder để làm cho nó hoạt động (iOS 8.3). Video của tôi khá ngắn (3 giây). – Chris

1

Có thể có vấn đề với đường dẫn tương đối ../ bạn đang sử dụng. Hãy thử sử dụng đường dẫn tuyệt đối đầy đủ - bắt đầu bằng http://.

4

Một trong những cách mà video có thể không phát trong UIWebView là nếu máy chủ lưu trữ tệp video không hỗ trợ phạm vi byte. UIWebView không tải xuống toàn bộ tệp .mp4 cùng một lúc; thay vào đó, nó phát video bằng cách yêu cầu các phần của tệp. Hầu hết các máy chủ trong những ngày này đều hỗ trợ phạm vi byte, nhưng nếu máy của bạn không có hoặc nếu bạn đã tắt tính năng này vì một số lý do, bạn sẽ không thể phân phối video tới thiết bị iOS.

0

Tôi cũng có vấn đề này, tôi có 2 .mp4 nhưng có thể sử dụng và không, tôi cố gắng định dạng loại tệp .mp4 thành .mp4 cho IPad và công việc, tôi nghĩ bạn nên thử.

-1

Để phát video mp4 trên lập trình iPhone không phải là rất khó. Chỉ cần chúng ta cần làm thêm một kéo và thả.

vui lòng thực hiện một dự án xem đơn mới. sau đó trong file ViewController.m chỉ cần sao chép và dán mã này

#import "ViewController.h" 

    @interface ViewController() 

    @end 

    @implementation ViewController 
    @synthesize webView; 
- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

CGRect screenRect = [[UIScreen mainScreen] bounds]; 

CGFloat screenWidth = screenRect.size.width; 
CGFloat screenHeight = screenRect.size.height; 

webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0,screenWidth,screenHeight)]; 


NSURL *url = [[NSBundle mainBundle] URLForResource:@"testingHTML" withExtension:@"html"]; 
NSLog(@"%@",url); 
[self.webView loadRequest:[NSURLRequest requestWithURL:url]]; 



// NSURL *nsurl=[NSURL URLWithString:url]; 
//NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; 
// [webView loadRequest:nsrequest]; 
[self.view addSubview:webView]; 





} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

@end 

Sau đó tạo file HTML có tên là testingHTML.html

và sao chép và dán đoạn mã sau vào tập tin HTML

<!DOCTYPE html> 
<html> 
<head></head> 

<body> 
    <center> <video width="250" height="304" controls preload> 
     <source src="video1.mp4" type="video/mp4"> 
      </video> </center> 

    <p>Thanks to Md Kamrul Hasan [email protected]</p> 

    </body> 
</html> 

Kéo và thả video thuộc loại MP4 ở hai nơi:

Đầu tiên: Kéo video từ HDD vào tab dự án [Tab bên trái của Xcode] Thứ hai: Từ tab Xcode bên trái, một lần nữa CỜ TẬP TIN VIDEO TỚI cho Dự án ---> Giai đoạn Xây dựng ---> Sao chép Tài nguyên Gói

Thông thường, tệp Sao chép có tệp dự án nhưng một số lần chúng không chứa tệp video.

NGAY CHẠY dự án và THAM GIA video ...... !!

Chúc may mắn

+0

https://drive.google.com/file/d/0B-YyYsAL0QKLRWJRdHVxbXhwNUU/view?usp=sharing –

+0

Tôi cố gắng phát hai video trong hai lần xem web nhưng chỉ phát video đơn. –

Các vấn đề liên quan